ScanSkill

Lifecycle of Components

 The lifecycle of components is the series of methods that pass through different stages of the component’s existence. We can monitor and manipulate these different phases of the lifecycle. There are four main phases of the lifecycle:

  1. Initialization
  2. Mounting
  3. Updating
  4. Unmounting

Initialization

This is the first phase where the props and state of a component are initialized inside the constructor() of a class.

Mounting

Mounting is the phase of rendering the JSX elements in the DOM. the mounting phase has three methods that gets called:

  1. getDerivedStateFromProps()
  2. render()
  3. componentDidMount()

Updating

Updating is a phase when a component is updated. Whenever there is a change in the component's state or props,the component is updated. The updating phase has five methods that gets called during this phase.

  1. getDerivedStateFromProps()
  2. shouldComponentUpdate()
  3. render()
  4. getSnapshotBeforeUpdate()
  5. componentDidUpdate()

Unmounting

 Unmounting is the final step of the component lifecycle where the component is removed or unmounted from the DOM.

The componentWillUnmount() is called while unmounting the component