Home  >  Article  >  Web Front-end  >  What are the stages of react components?

What are the stages of react components?

王林
王林Original
2020-11-27 10:10:412066browse

The react component has five stages: Initialization, Mounting, Updating, Unmounting and Error Handing. The Error Handing phase belongs to the error handling phase.

What are the stages of react components?

The environment of this article: windows10, react16, this article is applicable to all brands of computers.

(Learning video sharing: react video tutorial)

There are four different stages in the component life cycle:

Initialization: In this stage , the component is ready to set initialization state and default properties.

Mounting: The react component is ready to be loaded onto the DOM. This phase contains the getDerivedStateFromProps and componentDidMount life cycle methods.

Updating: At this stage, the component is updated in two ways, sending new properties and updating status. This phase contains getDerivedStateFromProps, shouldComponentUpdate, getSnapshotBeforeUpdate and componentDidUpdate life cycle methods.

Unmounting: At this stage, the component is no longer needed and is unmounted from the browser DOM. This phase contains the componentWillUnmount lifecycle method.

In addition to the above four common life cycles, there is also an error handling stage:

Error Handling: In this stage, whether in the rendering process, in the life cycle method or If an error occurs in the constructor of any child component, the component will be called. This phase contains the componentDidCatch life cycle method.

Related recommendations: js tutorial

The above is the detailed content of What are the stages of react components?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn