-
-
Save tkdn/f56c43632b4721aac89dda59b08a2638 to your computer and use it in GitHub Desktop.
Redux container
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
// 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