What are some differences between updating and unmounting of a component?

Question

In the context of this exercise, what are some differences between updating and unmounting of a component?

Answer

Although they share some similarities, such as being phases of a React component lifecycle and having optional methods that can be overridden, updating and unmounting of a component have some important differences.

The updating phase of a React component happens after the mounting phase, and before the unmounting phase. This phase can be thought of like the time when a component is “living”. The five lifecycle methods which were covered in this lesson will run any time the component updates and will continue this cycle until the component is eventually unmounted.

The unmounting phase of a component lifecycle occurs when the component is being removed from the DOM permanently, such as when the page is reloaded or has been removed using some function. It can be thought of like the time when a component is “terminated”. During this phase, only one method, componentWillUnmount, will be run.

1 Like