title: Why is React setState hook not updating immediately?
body: <p>I am trying to call a handler from a parent function with the updated state value as an argument, however, the state does not update immediately after the setSelected is called as both console logs are printing false(the initial value). After the onClick function is completed however, it gets updated.</p>
  <pre><code>onClick={() =&gt; {
          console.log(&quot;Clicked: &quot;, props.rank, props.suit, selected); 
          setSelected(!selected)
          console.log(&quot;selected: &quot;, selected)
          // props.handle_card_selected(props.id, selected)
        }}
  </code></pre>
  <pre><code>useEffect(() =&gt; {
      const check_border = () =&gt; {
        if (selected) {
          return &quot;green&quot;
        }
        return &quot;black&quot;
      }
      check_border()
    }, [selected])
  </code></pre>