react on update code example
Example 1: componentDidUpdate
componentDidUpdate(prevProps, prevState) {
if (prevState.pokemons !== this.state.pokemons) {
console.log('pokemons state has changed.')
}
}
Example 2: shouldcomponentupdate
shouldComponentUpdate(nextProps, nextState) {
return true;
}
Example 3: component did mmount
componentDidUpdate(prevProps, prevState, snapshot)
Example 4: react lifecycle
constructor(props) {
super(props);
this.state = { counter: 0 };
this.handleClick = this.handleClick.bind(this);
}