React Component lifecycle
28 April 2022 (Updated 1 September 2022)
On this page
In a nutshell
React components undergo several stages as they are created, initialized, updated, and destroyed:
- Component constructor is called. State and props are initialized with their default values.
- Component’s
render()
method is called. React updates the DOM with therender()
method’s output. - Once the component’s output is inserted in the DOM, React calls its
componentDidMount()
method. - If the component is removed from the DOM, React calls its
componentWillUnmount()
method.
Here‘s a diagram that visualizes these stages.
Note: React’s Strict Mode alters the lifecycle behaviour by double-invoking some methods like render
. If you are trying to understand the component lifecycle by tinkering with the lifecycle methods, you might want to turn off Strict Mode.
More comprehensive lifecycle reference
- Mounting
- Updating
- Unmounting
- Error handling
Sources
TODO
- Visualize the process.
Tagged:
React
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment