Skip to content

Instantly share code, notes, and snippets.

@tmeasday
Last active June 16, 2017 14:28
Show Gist options
  • Save tmeasday/86332f162a0bf5912d330acabab88bdd to your computer and use it in GitHub Desktop.
Save tmeasday/86332f162a0bf5912d330acabab88bdd to your computer and use it in GitHub Desktop.
Redux container
// This is a vastly simplified implementation of what a Redux container would do
class MyComponentContainer extends Component {
mapStateToProps(state) {
// this function is specific to this particular container
return state.foo.bar;
}
render() {
// This is how you get the current state from Redux,
// and would be identical, no mater what mapStateToProps does
const { state } = this.context.store.getState();
const props = this.mapStateToProps(state);
return <MyComponent {...this.props} {...props} />;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment