📜  reactjs 生命周期类组件 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:33.360000             🧑  作者: Mango

代码示例1
import React from 'react';
import ReactDOM from 'react-dom';
 
class Test extends React.Component {
    constructor(props)
    {
        super(props);
        this.state = { hello : "World!" };
    }
 
    componentWillMount()
    {
        console.log("componentWillMount()");
    }
 
    componentDidMount()
    {
        console.log("componentDidMount()");
    }
 
    changeState()
    {
        this.setState({ hello : "Geek!" });
    }
 
    render()
    {
        return (
            
            

GeeksForGeeks.org, Hello{ this.state.hello }

            

            Press Here!             

            
);     }       shouldComponentUpdate(nextProps, nextState)     {         console.log("shouldComponentUpdate()");         return true;     }       componentWillUpdate()     {         console.log("componentWillUpdate()");     }       componentDidUpdate()     {         console.log("componentDidUpdate()");     } }   ReactDOM.render(     ,     document.getElementById('root'));