componentdidupdate react example
Example 1: prev props
componentDidUpdate(prevProps) {
// Utilisation classique (pensez bien à comparer les props) :
if (this.props.userID !== prevProps.userID) {
this.fetchData(this.props.userID);
}
}
Example 2: shouldcomponentupdate
shouldComponentUpdate(nextProps, nextState) {
return true;
}
Example 3: component did mmount
componentDidUpdate(prevProps, prevState, snapshot)