Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This removes async validation from Formik. (See #1524)
As for actually rolling this out, and once we figure out details, my plan would be to add check for promise in validation and put up a deprecation notices for a few releases. Since sync/async have different typescript types, I think we can make a new top-level entry called
formik/sync
. We will need to add docs and update examples.Why?
When we first wrote Formik, the only reason we had async validation at all was because Yup was async. Yup has added an sync API since then. In addition, I can count on a single hand the number of times I have used async validation at the top level. In fact, when I tried a few months back to make a username checker input, I ended up not using formik validate prop on that form because you can't debounce it properly (you want to debounce on changes/blur but then not during submit). Thus it's only purpose is really to support Yup at this point. I will add more docs about best practices later, but I've found it way easier to do this sort async remote validation in a custom field or in a custom effect. The only perhaps nuance to removing this is that it's theoretically possible that you may want to validate asynchronously "prior to submit." With this change, you would move that call to be at the top of your own onSubmit function. I'm not sure this actually matters in practice though as long as your API validates (which it should anyways).
FWIW you'll be able to mimic most of the old behavior for top level async validate by just wrapping useFormik.
Alternatives