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.
const [err,setError]=useState("")
const [password,setPassword]=useState("")
function handlePassword(event){
setPassword(event.target.value);
if(password.length<6){
console.log(password)
setError("password should contain 6 character")
}else if(!isInclude(password)){
setError("password should contain a special character")
}else{
setError("")
}
}
<input type="password" placeholder="password" required className="form-input" value={password} onChange={handlePassword} name="password" onClick={clearInput}/>