I have to click log in twice before it chacks the data. Can someone help why?
I'm creating a forum website and on my log-in page the user has to click the button twice before it the code validates and responds to the given data.
here is my handle submit which is triggered on button click.
const [values,setValues] =useState({
email: '',
password: ''
})
const navigate =useNavigate();
const [errors, setErrors] = useState({})
const handleInput = (e) => {
setValues(prev => ({...prev, [e.target.name]: [e.target.value]}))
}
const handleSubmit = (e) => {
e.preventDefault()
setErrors(Validation(values))
if(errors.password === "" && errors.email === ""){
axios.post('http://localhost:8081/login', values)
.then(res => {
if(res.data.errorMessage ==='Success'){
navigate('/dashboard');
}
else{
console.log(res.data.errorMessage);
}
})
.catch(err => console.log(err));
}
};
PS validation returns error messages when spots are not filled properly
I'm new to nodejs and react so if anyone could explain it would be a huge help!