setstate() js code example

Example 1: setstate react js

constructor(props) {
        super(props);
        this.state = {
            isActive: true,
        };
    }

    checkStatus = () => {
        this.setState({		// use this function
            'isActive' : !this.state.isActive,
        });
    }

Example 2: lifecycle method react

INITIALIZATION= setup props and state 
MOUNTING= constructor->componentWillMount->render->componentDidMount//Birth
UPDATE= shouldComponentUpdate->componentWillUpdate->render
  		->componentDidUpdate //Growth
UNMOUNTING= componentWillUnmount //Death

Example 3: setstate in react

Functional Component
const [counter, setCounter] = useState(0);

setCouter(counter + 1);

Example 4: react setState

this.setState({
      date: new Date()
    });

Example 5: component did mmount

componentDidUpdate(prevProps, prevState, snapshot)