Open gracekrcx opened 3 years ago
If you are trying to access Formik state via context, use useFormikContext. Only use this hook if you are NOT using or withFormik.
useFormikContext
is a custom React hook that will return all Formik state and helpers via React Context.
React hook
onSubmit: (values: Values, formikBag: FormikBag) => void | Promise<any>
onSubmit={(values, actions) => { setTimeout(() => { alert(JSON.stringify(values, null, 2)); actions.setSubmitting(false); }, 1000); }}
官網提到 Use cases for useFormik
另外一段 useFormik 的解釋
If you are trying to access Formik state via context, use or withFormik.
useFormikContext
. Only use this hook if you are NOT usinguseFormikContext
is a custom
React hook
that will return all Formik state and helpers via React Context.