title: React useState() doesn't update value synchronously
body: <p>React useState() doesn't update value of the variable if called just after setting value.</p>
  
  <p>I read about useEffect(), but don't really know how this will be useful for this particular scenario.</p>
  
  <p><strong><a href="https://codesandbox.io/s/nifty-yonath-38iiv?fontsize=14" rel="noreferrer">Full code</a></strong> (please open the console tab to see the variable status)</p>
  
  <h1>UPDATE</h1>
  
  <pre><code>// hook
  const [ error, setError ] = useState&lt;boolean&gt;();
  const handleSubmit = (e: any): void =&gt; {
      e.preventDefault();
      if (email.length &lt; 4) {
        setError(true);
      }
      if (password.length &lt; 5) {
        setError(true);
      }
      console.log(error); // &lt;== still false even after setting it to true
      if (!error) { 
        console.log("validation passed, creating token");
        setToken();
      } else {
        console.log("errors");
      }
    };
  </code></pre>