The right place to check for state change is either to pass callback as second argument to setState
method
this.setState({
explanation: 'phil says so'
},() => {
console.log('Set the explanation state successfully')
})
or using componentDidUpdate lifecycle method.
componentDidUpdate(prevProps, prevState){
if (prevState.explanation !== this.state.explanation) {
console.log('Set the explanation state successfully')
}
}
* Be the first to Make Comment