So I am doing a form validation onBlur and I am using RTK query for calling the api. The problem I am facing is that on the very first API call the isSuccess
is returning false even though the API return status is 200
const [validateUser, { data, isSuccess }] = authAPI.useValidateUserMutation();
const validateUserDetails = (name, event) => {
event.preventDefault();
if (event.target.value !== "") {
let fieldData = {
fieldName: name,
value: event.target.value,
};
validateUser(fieldData);
console.log("Is Success: ", isSuccess);
if (isSuccess && data.errors.status !== 200) {
console.log(data);
}
} else {
}
};
During the first time validating
Even though the status is API status is 200 success is returned false but now if I do it again it will return true
Is there a way to solve this?