DEV Community

NEYAZ NAFIZ
NEYAZ NAFIZ

Posted on • Updated on

React component lifecycle.

In React, a component's lifecycle refers to the events that occur from initialization to destruction. React components undergo three main phases: Mounting, Updating, and Unmounting. Each phase has a set of lifecycle methods that you can override to perform actions at specific points in the component's life.

Basically, the React Component lifecycle has 3 stages:

  1. Mount.
  2. Update.
  3. UnMounting.

    • Mount : 'Initial Stage' This stage starts when any component enters into DOM, here are four methods in this stage.
  4. constructor()

  5. getDerivedStateFromProps()

  6. render()

  7. componentDidMount()

    • Updating : When any changes of props or state make changes in the component, then the component enters this stage. here are five methods in this stage.
  8. getDerivedStateFromProps()

  9. shouldComponentUpdate()

  10. render()

  11. getSnapshotBeforUpdate()

  12. componentDidUpdate()

    • UnMounting : When any component is excluded from the DOM, then the component enters this stage. get here done one method in this stage.
  13. componentWillMount()

An image of React Component Lifecycle -

Image description
(This image is collected from the internet)


Top comments (0)