Skip to content

Instantly share code, notes, and snippets.

@StevenLangbroek
Created December 29, 2015 21:33
Show Gist options
  • Save StevenLangbroek/6d31cd7838abd0920568 to your computer and use it in GitHub Desktop.
Save StevenLangbroek/6d31cd7838abd0920568 to your computer and use it in GitHub Desktop.
Redux glue
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} />
);
}
}
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