React LifecycleTwo pictures to help you understand the life cycle of React
class Life extends React.Component{ // Constructor constructor(props){ console.log('Life constructor ---constructor'); super(props) this.state={num:0} } // Calculate +1 function add=()=>{ const {num} = this.state this.setState({num:num+1}) } // Delete component death=()=>{ ReactDOM.unmountComponentAtNode(document.getElementById('text')) } force=()=>{ this.forceUpdate() } // Will mount componentWillMount(){ console.log('Life will be mounted --- componentWillMount'); } // Already mounted componentDidMount(){ console.log('Life has been mounted --- componentDidMount'); } // Delete trigger componentWillUnmount(){ console.log('Life deletion trigger --- componentWillUnmount'); } // Should the data be changed? shouldComponentUpdate(){ console.log('Does Life change data --- shouldComponentUpdate'); return true } // Data will be changed componentWillUpdate(){ console.log('Life is about to change data---componentWillUpdate'); } //Change datacomponentDidUpdate(){ console.log('Life changes data---componentDidUpdate'); } render(){ console.log('Life---render'); const {num} = this.state return( <div> <h1>Counter: {num}</h1> <button onClick={this.add}>Click me +1</button> <button onClick={this.death}>Delete</button> <button onClick={this.force}>Do not change any state of data, force update</button> </div> ) } } // Render the page ReactDOM.render(<Life />, document.getElementById('text')) Mounting steps Update steps delete Summary: Initialization phase: triggered by ReactDOM.render() — initial rendering React Lifecycle (New) Three Phases of the Life Cycle (New) Initialization phase: triggered by ReactDOM.render() — initial rendering
1.render: Initialize rendering or update rendering call
1.componentWillMount
This concludes this article about the React lifecycle questions that interviewers often ask. For more content related to the React lifecycle, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Summary of Linux system user management commands
>>: Detailed explanation of the underlying encapsulation of Java connection to MySQL
This article shares the specific code for canvas ...
What is a mata tag The <meta> element provi...
Dataframe is a new API introduced in Spark 1.3.0,...
To use standard CSS3 to achieve the shadow effect...
Recently, I found that the company's server t...
Table of contents 1. Project Environment 2. Proje...
1. First, an error message is reported when assoc...
This article shares the specific code for impleme...
Server Information Management server: m01 172.16....
Preface This article mainly introduces the releva...
This article records the installation of MySQL 8....
1. Docker imports local images Sometimes we copy ...
Create a project directory mkdir php Create the f...
difficulty Two mask creation of svg graphics Firs...
Table of contents Install tinymce, tinymce ts, ti...