-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
types: Align FormikHelpers and FieldHelper types to useFormik ones (#…
…3843) This is yet another PR around TypeScript. The inferred types for the helpers in `useFormik` are the correct ones and should be used everywhere. See ``` export declare function useFormik<Values extends FormikValues = FormikValues>({ validateOnChange, validateOnBlur, validateOnMount, isInitialValid, enableReinitialize, onSubmit, ...rest }: FormikConfig<Values>): { [...redacted for readability...] setFieldTouched: (field: string, touched?: boolean, shouldValidate?: boolean) => Promise<FormikErrors<Values>> | Promise<void>; setFieldValue: (field: string, value: any, shouldValidate?: boolean) => Promise<FormikErrors<Values>> | Promise<void>; setFieldError: (field: string, value: string | undefined) => void; setStatus: (status: any) => void; setSubmitting: (isSubmitting: boolean) => void; setTouched: (touched: FormikTouched<Values>, shouldValidate?: boolean) => Promise<FormikErrors<Values>> | Promise<void>; setValues: (values: React.SetStateAction<Values>, shouldValidate?: boolean) => Promise<FormikErrors<Values>> | Promise<void>; submitForm: () => Promise<any>; validateForm: (values?: Values) => Promise<FormikErrors<Values>>; validateField: (name: string) => Promise<void> | Promise<string | undefined>; [...redacted for readability...] }; ``` Having the correct types, and the awaiting these helpers helps with otherwise possible race conditions when used in an imperative way, like so ``` const handleChange = ({ target }) => { await setFieldTouched('fieldName', true, false) await setFieldValue('fieldName', target.value, false) await validateField('fieldName') } ```
- Loading branch information
Showing
4 changed files
with
24 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'formik': patch | ||
--- | ||
|
||
Fix FormikHelper and FieldHelperProps types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9e0a661
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.
Successfully deployed to the following URLs:
formik-docs – ./website
formik.org
formik-docs-git-main-formik.vercel.app
formik-docs.vercel.app
formik-docs-formik.vercel.app
www.formik.org