-
-
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
Make formik sync when validation functions are sync #3976
base: main
Are you sure you want to change the base?
Make formik sync when validation functions are sync #3976
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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. |
|
@jaredpalmer This change goes in the direction that you are mentioning in #2140 but is backwards compatible since it's not removing any functionality. The deprecation of the async validation methods could be done in a later stage so we can first make things more synchronous (which will improve performance of a lot of apps) and then proceed with the removal of the async stuff. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏🏻 Well done. Amazing update
packages/formik/src/Formik.tsx
Outdated
@@ -300,26 +294,43 @@ export function useFormik<Values extends FormikValues = FormikValues>({ | |||
prev = setIn(prev, fieldKeysWithValidation[index], curr); | |||
} | |||
return prev; | |||
}, {}) | |||
); | |||
}, {} as FormikErrors<Values>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should be able to move this type in the .reduce<FormikErrors<Values>>
}, {} as FormikErrors<Values>); | |
}, {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need it to be casted in the .reduce
I think, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should give you the same outcome
fieldErrorsList.reduce<FormikErrors<Values>>((prev, curr, index) => {
if (curr === 'DO_NOT_DELETE_YOU_WILL_BE_FIRED') {
return prev;
}
if (curr) {
prev = setIn(prev, fieldKeysWithValidation[index], curr);
}
return prev;
}, {})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is does. Generics and casting are essentially the same thing though 🙁
I made the change anyway
When the given validation function are synchronous there is no reason to make them async. Making them async actually makes the whole code much slower and creates unecessary re-renders.