Created
December 29, 2015 21:33
-
-
Save StevenLangbroek/6d31cd7838abd0920568 to your computer and use it in GitHub Desktop.
Redux glue
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 characters
| import React from 'react'; | |
| // Higher order component taking care of subscribing | |
| export default (Component) => class ReduxComponent extends React.Component { | |
| componentDidMount(){ | |
| const { store } = this.context; | |
| this.unsubscribe = store.subscribe(() => this.forceUpdate()); | |
| } | |
| componentWillUnmount(){ | |
| this.unsubscribe(); | |
| } | |
| render(){ | |
| return ( | |
| <Component {...this.props} /> | |
| ); | |
| } | |
| } |
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 characters
| import React from 'react'; | |
| import subscribe from './subscribe'; | |
| class EventChooserScreen extends React.Component { | |
| render(){ | |
| return ( | |
| <div>Events yo!</div> | |
| ); | |
| } | |
| } | |
| // And here's how you use it: | |
| export default subscribe(EventChooserScreen); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment