That's because by the time you returning your isAuth
value the new user value
is not set yet. you need to know that React setState
is asynchronous function.
just use the the boolean itself directly like this:
setUser(true);
return { status: response.data.Status, isAuth: true }
or in case of a rejection:
setUser(false);
return { status: undefined, message: err, isAuth: false };
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…