title: useState value is one step behind in reactjs
body: <p>I am working on a login/register page in react  and I use useState hooks for check if the password is strong or not. and display user what should he  do to make his password stronger. But  I noticed that
  when user is typing in the password field their is a delay in updating the password in the useState (in the console.log() of function handlePassword) . Therefore my function handlePassword is not working properly.</p>
  <pre><code>  const [err,setError]=useState(&quot;&quot;)
    const [password,setPassword]=useState(&quot;&quot;)
  
     function handlePassword(event){
        setPassword(event.target.value);
        if(password.length&lt;6){
          console.log(password)
          setError(&quot;password should contain 6 character&quot;)
        }else if(!isInclude(password)){
           setError(&quot;password should contain a special character&quot;)
          
        }else{
          setError(&quot;&quot;)
        }
        
  
      }
  </code></pre>
  <pre><code>   &lt;input type=&quot;password&quot; placeholder=&quot;password&quot; required className=&quot;form-input&quot; value={password} onChange={handlePassword} name=&quot;password&quot;  onClick={clearInput}/&gt;  
  
  </code></pre>