title: Wait for state to update when using hooks
body: <p>How do I wait for state to update using Hooks. When I submit my form I need to check if <code>termsValidation</code> is false before running some additional code. If the state has just changed it doesn't pick up on this. </p>
  
  <pre><code>import React, { useState } from 'react';
  
  export default function Signup() {
    const [terms, setTerms] = useState('');
    const [termsValidation, setTermsValidation] = useState(false);
  
    function handleSubmit(e) {
      e.preventDefault();
  
      if (!terms) {
        setTermsValidation(true);
      } else {
        setTermsValidation(false);
      }
  
      if (!termsValidation) {
        console.log('run something here');
      }
    }
  
    return (
      &lt;div&gt;
        &lt;form&gt;
          &lt;input type="checkbox" id="terms" name="terms" checked={terms} /&gt;
  
          &lt;button type="submit" onClick={handleSubmit}&gt;
            Sign up
          &lt;/button&gt;
        &lt;/form&gt;
      &lt;/div&gt;
    );
  }
  </code></pre>