Home > Article > Web Front-end > What are the stages of react components?
The react component has five stages: Initialization, Mounting, Updating, Unmounting and Error Handing. The Error Handing phase belongs to the error handling phase.
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!