Open Jestermaxrko opened 8 months ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
formik-docs | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Apr 11, 2024 10:40pm |
Latest commit: e004b643077cd54ff52ad4b18ddb6001ebe87d2b
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Helpful change. Are we pending one more review to get this merged?
Thank you very much. I hope it will be released.
Would love a test please
I think I see some of the source of confusion, in Formik.tsx
stateRef.current
is saved to state
but the issue is that ref is wholly-replaced inside of dispatch
. We should probably remove that variable altogether because it is a quiet source of bugs.
Any chance this can get merged and released? Seems like a helpful change to keep on the shelf.
Fixes issue - https://github.com/jaredpalmer/formik/issues/2083
The cause of the issue is in this line https://github.com/jaredpalmer/formik/blob/0f960aaeeb0bdbef8312b5107cd3374884a0e62b/packages/formik/src/Formik.tsx#L185
beause of assigning value from
stateRef.current
to thestate
variable this variable contains "old" value until next re-render https://github.com/jaredpalmer/formik/blob/0f960aaeeb0bdbef8312b5107cd3374884a0e62b/packages/formik/src/Formik.tsx#L190And then when
setFieldValue
andsetFieldTouched
are called consecutivelystateRef.current
references to updated value imediatelly aftersetFieldValue
call, butstate
variable is still references to the old value andsetFieldTouched
runs validation on that old valueUsing
stateRef.current
directly gurantees that actual values are taken