title: UseState shows previous value always
body: <p>This is a popular question among all the new react developers but somehow I'm not able to understand the logic behind available solutions. I'm trying to update the state variable using hooks and trying it read the updated value but always it returns a previous value instead of new value. Below is the sequence of my code execution.</p>
  
  <pre><code>onClick={setTransactionAccountId}
  </code></pre>
  
  <p>on button click, it executes the below code and updates the state but the <code>console.log</code> shows the old value.</p>
  
  <pre><code>const [accountId, setAccountId] = useState(0);
  
  const setTransactionAccountId = e =&gt; {
    console.log("Clicked ID:", e.currentTarget.value);
    setAccountId(e.currentTarget.value);
    console.log("accountId:", accountId);
  };
  </code></pre>
  
  <p><strong><em>console log:</em></strong></p>
  
  <ol>
  <li><em>first button click:</em></li>
  </ol>
  
  <p>Clicked ID: 0
  accountId: 0</p>
  
  <ol start="2">
  <li><em>second button click:</em></li>
  </ol>
  
  <p>Clicked ID: 1
  accountId: 0</p>
  
  <p>could anyone please tell me the reason behind this behaviour and how to tackle it.</p>