componentDidUpdate() method is called after the component is updated.
It is called in Updating phase.
We can update state inside componentDidUpdate() method but must apply condition, otherwise it will run infinite loop.
Example 1 :
Example 2 - componentDidUpdate() with Parameters :
componentDidUpdate(prevProps, prevState, snapshot) method contains three parameters :
- prevProps - Stores value of previous props.
- prevState - Stores value of previous state.
- snapshot - Default value of snapshot is undefined.
Output :
Interview Questions
- Can we call API inside componentDidUpdate() method ?
Yes - Which method is called first componentDidUpdate() or shouldComponentUpdate()?
shouldComponentUpdate()
Comments
Post a Comment