-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding notifyOnChange as a side effect to succesful handleChange #1397
Conversation
Yes please! |
@jaredpalmer can we merge this? or if you have any other solution in mind, please revert back. |
Need this! 👍 |
Need something like this. Please consider merging. |
@jaredpalmer after jumping around a few issues referencing the same problem I realized there are a lot of people facing it. The form level |
Maybe this PR isn't required since it's possible to achieve with the existing API. See my comment in #271 (comment) |
This is possible with the existing API. There is no need for this addition. |
hi @jaredpalmer culd you please add some ref to existing solution, i think a lot of people end here with some googleing :) so we could prevent reopens or duplicates :) |
Boo!!! no fun!!! |
For me, this article here helped: https://plainenglish.io/blog/how-to-listen-to-formik-onchange-event-in-react |
An important advantage of the approach proposed in this PR (and the other linked threads), compared to the When you use a
This is unnecessary! It creates visible lag and jank, in addition to useless renders. The React docs "You Might Not Need an Effect" are all about how to remove instances of this general pattern of using effects to observe changes and call state setters. Effects are for subscribing to external stores or managing event listeners on imperative components, not communicating React state around. If Formik exposed an |
Description
This PR adds a side-effect to formik's
handleChange
which can be used to react to any update to formik form state.The effect is similar to formik-effect except built into formik itself without the need to install any additional library or retrofitting formik's validate hook to perform the callback.
Usage
In my project I had to broadcast a form dirty signal whenever user begins typing on it. This I implemented by triggering said signal from validate.
While this works for my use case, I cannot now make the form validate on blur as this would delay triggering of dirty signal.
If this change gets accepted, the users can add their own callback to react to formik state update like this: