Web / ReactJS Interview questions
What are the lifecycle methods of class Component in React?
The lifecycle methods are executed in the following order when a component instance being created and inserted into the DOM.
Mounting:
- constructor()
- static getDerivedStateFromProps()
- render()
- componentDidMount()
Updating:
- static getDerivedStateFromProps()
- shouldComponentUpdate()
- render()
- getSnapshotBeforeUpdate()
- componentDidUpdate()
Unmounting:
- componentWillUnmount() is called when a component is being removed from the DOM.
Error Handling:
These methods are called when there is an error during rendering, in a lifecycle method, or in the constructor of any child component.
- static getDerivedStateFromError()
- componentDidCatch()
More Related questions...