In the onBlur handler of an <input>, when manually calling setFieldValue and setFieldTouched in this order, and only doing validation on setFieldTouched, an outdated value will be validated.
Expected behavior
The order of setFieldValue and setFieldTouched should be irrelevant when the shouldValidate parameter is set to true only on the last one of the two calls.
Reproducible example
In the example, type in some value in the text field and then blur it. On blur, a different value is set to the state, but validation uses the outdated value before the state has been set.
Bug report
Current Behavior
In the
onBlur
handler of an<input>
, when manually callingsetFieldValue
andsetFieldTouched
in this order, and only doing validation onsetFieldTouched
, an outdated value will be validated.Expected behavior
The order of
setFieldValue
andsetFieldTouched
should be irrelevant when theshouldValidate
parameter is set totrue
only on the last one of the two calls.Reproducible example
In the example, type in some value in the text field and then blur it. On blur, a different value is set to the state, but validation uses the outdated value before the state has been set.
https://codesandbox.io/s/formik-validation-bug-1ot7yy
Suggested solution(s)
Not sure, probably the reducer needs to be fixed.
Additional context
It used to work correctly in an older Formik version (e.g. 1.2.0).
Your environment