title: ReactJS: setState using if else
body: <p>I am new to ReactJS. On my index page, the initial state of loginState &amp; modalStatus is false. I am trying to change modalStatus to true inside componentDidMount().</p>
  
  <pre><code>class Home extends Component {
    constructor(props) {
      super(props);
      this.state = {
        isLoggedIn: true,
        modalStatus: false,
      };
    }
  
    componentDidMount() {
      if(this.state.isLoggedIn) {
        console.log(this.state.modalStatus);
        this.setState({ modalStatus: true});
        console.log(this.state.modalStatus);
      }  else {
          console.log(this.state.modalStatus);
      }
    render() {
      return (
        &lt;&gt;
         &lt;h1&gt;Hello&lt;/h1&gt;
        &lt;/&gt;
      );
    }
  }
  </code></pre>
  
  <p>But my console is printing false for both modalStatus even after setState. Is there anything I am doing wrong? Please guide me. I would appreciate any helps.</p>