I'm using validationSchema of formik and the validationOnBlur is set to true. I want to make an API call onBlur based on the result of validation on that field. I tried running both the Formik's field OnBlur and my custom onBlur (for making an API call) but the errors object returns empty for the very first time in the custom onBlur function.
import { Field } from 'formik';
<Field
{...props}
render={({ field, form: { errors, touched } }) => (
<CustomComponent
{...props}
{...field}
value={field.value || ''}
onBlur={(e) => {
if (field.onBlur) {
//Formik's field onBlur that runs validation
field.onBlur(e);
}
if (props.onBlur) {
//custom onBlur which is going to make the API call.
props.onBlur(e);
}
What's the best possible way to get the updated error object or figure out that there is an error before making an API call?
I'm using validationSchema of formik and the validationOnBlur is set to true. I want to make an API call onBlur based on the result of validation on that field. I tried running both the Formik's field OnBlur and my custom onBlur (for making an API call) but the errors object returns empty for the very first time in the custom onBlur function.
What's the best possible way to get the updated error object or figure out that there is an error before making an API call?