Skip to content
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

Call validateFormWithLowPriority with correct values #2025

Merged

Conversation

sgronblo
Copy link
Contributor

Fixes #1977

  • When using setValues dispatch is called with type: SET_VALUES and
    payload: values. However the state update happens asynchronously so when
    validateFormWithLowPriority is called, state.values still hasn't
    been updated.
  • This fix improves the assertion for the setValues
    validation to test to confirm that the expected value is given to
    Formik's validate function.
  • The fix itself is to call validateFormWithLowPriority with the
    values parameter given to setValues itself, instead of waiting for
    the useReducer to update the state. Currently it does not seem to be
    possible to wait for dispatch to have completed.

- When using `setValues` `dispatch` is called with type: SET_VALUES and
payload: values. However the state update happens asynchronously so when
`validateFormWithLowPriority` is called, `state.values` still hasn't
been updated.
- This fix improves the assertion for the `setValues`
validation to test to confirm that the expected value is given to
Formik's validate function.
- The fix itself is to call `validateFormWithLowPriority` with the
`values` parameter given to `setValues` itself, instead of waiting for
the `useReducer` to update the state. Currently it does not seem to be
possible to wait for `dispatch` to have completed.
@vercel
Copy link

vercel bot commented Nov 13, 2019

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/jared/formik-docs/r5wj3ppe6
🌍 Preview: https://formik-docs-git-fork-sgronblo-validate-correctly-with-setvalues.jared.now.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v2] Form-level validation runs on old values
2 participants