Skip to content

Instantly share code, notes, and snippets.

@nightspirit
Created April 11, 2018 08:27
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 nightspirit/91290d9e187bb46d9578804ba0d4a414 to your computer and use it in GitHub Desktop.
Save nightspirit/91290d9e187bb46d9578804ba0d4a414 to your computer and use it in GitHub Desktop.
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