componentdidupdate example
Example 1: component did update arguments
componentDidUpdate(prevProps, prevState) {
if (prevProps.data !== this.props.data) {
this.chart = c3.load({
data: this.props.data
});
}
}
Example 2: componentDidUpdate
componentDidUpdate(prevProps, prevState) {
if (prevState.pokemons !== this.state.pokemons) {
console.log('pokemons state has changed.')
}
}
Example 3: componentdidupdate arguments
componentDidUpdate(prevProps, prevState) {}
Example 4: lifecycle method react
INITIALIZATION= setup props and state
MOUNTING= constructor->componentWillMount->render->componentDidMount
UPDATE= shouldComponentUpdate->componentWillUpdate->render
->componentDidUpdate
UNMOUNTING= componentWillUnmount
Example 5: component did mmount
componentDidMount()
Example 6: component did mmount
componentDidUpdate(prevProps, prevState, snapshot)