I try to update the values in the useState with the fetched data. when I console.log data.success it returns true. Then I assign it to the success value. but it returns false! why? why value success doesn't get updated immediately. At the end i receive the message from the server that the login was successful. SIGN IN success: false the user admin is logged
const Signin = () => {
const [values, setValues] = useState({
success: false
});
const { success } = values;
const clickSubmit = async event => {
event.preventDefault();
const signReact = catchAsync(async (email, password) => {
const data = await signin(email, password) // fetch data from the server
console.log(data.success); // -> true
if (data) {
setValues({
...values, success: data.success // -> assign to success
});
console.log("SIGN IN success: " + success); // -> false! why?!
}
return data;
});
signReact(email, password);
};