Created
November 20, 2017 08:31
-
-
Save oliverbenns/dcc7f2c5e23a7a63b5a39b40b9a1a75e to your computer and use it in GitHub Desktop.
Revisions
-
oliverbenns renamed this gist
Nov 20, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
oliverbenns created this gist
Nov 20, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ import React from 'react'; const visible = isVisible => Component => { class VisibleComponent extends React.Component { componentDidMount() { this.unsubscribe = this.context.store.subscribe(this.handleChange.bind(this)); } componentWillUnmount() { this.unsubscribe(); } handleChange() { this.forceUpdate(); } render() { const show = isVisible(this.context.store.getState()); if (!show) { return null; } return <Component {...this.props} />; } } VisibleComponent.contextTypes = { store: React.PropTypes.object }; return VisibleComponent; }; export default visible;