reactjs lifecycle class components 1

reactjs lifecycle class components

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'));

Here is what the above code is Doing:
1. The componentWillMount() method is called before the render() method.
2. The componentDidMount() method is called after the render() method.
3. The shouldComponentUpdate() method is called before the render() method.
4. The componentWillUpdate() method is called before the render() method.
5. The componentDidUpdate() method is called after the render() method.

Similar Posts