Phase 2: Mounting
The second phase of the React component lifecycle, followed by the initialization phase, is the mounting phase. It commences when the component is positioned over the DOM container and rendered on a webpage. It consists of 2 methods, namely:
- componentWillMount(): The method invoked immediately before the component is positioned on the DOM, i.e. right before the component is rendered on the screen for the very first time.
- componentDidMount(): The method invoked immediately after the component is positioned on the DOM, i.e. right after the component is rendered on the screen for the very first time.
What are the different phases of ReactJS component lifecycle ?
In React JS, the development of each component involves the use of different lifecycle methods. All the lifecycle methods used to create such components, together constitute the component’s lifecycle. They are defined as a series of functions invoked in various stages of a component.
There are primarily 4 phases of a lifecycle as follows.
Table of Content
- Initializing
- Mounting
- Updating
- Unmounting