What is the full lifecycle and methods of a component?

Question

What is the full lifecycle and methods of a component?

Answer

As covered in the Codecademy lessons, there are three main phases of a component’s lifecycle, and each phase has a set of methods that will run in sequence.

The first phase of a component’s lifecycle is the Mounting phase. This is when a component is created and inserted into the DOM. The methods that run during this phase, in order, are

componentWillMount()
render()
componentDidMount()

The next phase of a component’s lifecycle is the Updating phase. This is when a component undergoes any changes to props or state. This phase is the main part of a component’s life, and the following methods will be invoked repeatedly at each change,

componentWillReceiveProps()
shouldComponentUpdate()
render()
componentDidUpdate()

The last phase of a component’s lifecycle is Unmounting. This is when the component is removed from the DOM, and the only method run during this phase is

componentWillUnmount().

1 Like