Skip to content

Instantly share code, notes, and snippets.

@Jahans3
Last active December 6, 2018 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jahans3/4dbc491098732fce0080319b73f75aca to your computer and use it in GitHub Desktop.
Save Jahans3/4dbc491098732fce0080319b73f75aca to your computer and use it in GitHub Desktop.
Final ConnectState
class ConnectState extends React.Component {
state = {};
static getDerivedStateFromProps ({ state, mapState = s => s }) {
return mapState(state);
}
shouldComponentUpdate (nextProps, nextState) {
return shallowCompare(this.state, nextState);
}
render () {
return this.props.children({
state: this.state,
dispatch: this.props.mapDispatch ? this.props.mapDispatch(this.props.dispatch) : this.props.dispatch
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment