Last active
June 16, 2017 14:28
-
-
Save tmeasday/86332f162a0bf5912d330acabab88bdd to your computer and use it in GitHub Desktop.
Redux container
This file contains 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
// 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