Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
React 16.3 lifecycle hook
// before
componentWillUpdate(nextProps, nextState) {
if (
this.state.someStatefulValue !==
nextState.someStatefulValue
) {
nextProps.onChange(nextState.someStatefulValue);
}
}
//after
componentDidUpdate(prevProps, prevState) {
if (
this.state.someStatefulValue !==
prevState.someStatefulValue
) {
this.props.onChange(this.state.someStatefulValue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment