So I am doing a basic validation in my React App. I am using react-final-form and what the validation does it returns an object of errors, if they exists. For one set of my validation I am using an async function and it always returns Promise{<pending>}
. I am not sure why because all my await methods are closed with a .then()
; Please have a look at my code:
async function checkEmail(email) {
const result = await axios
.post(`/api/check-email`, { values: email })
.then(e => e.data.exists);
return result;
}
// main validation object
const validation: async values => {
const errors = {};
if(!values.email) {
errors.email = "Email is required"
} else {
const response = await checkEmail(values.email).then(e => { return e; });
if(response) {
errors.email = "Email taken!"
}
}
return errors;
}
Once the email is validated and if the response returns false the validation should return an empty object like {}
however it returns Promise {<pending>}
.
Thank you!