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