gracekrcx / weekly-notes

4 stars 0 forks source link

該用 useFormikContext 還是 useFormik #106

Open gracekrcx opened 3 years ago

gracekrcx commented 3 years ago

官網提到 Use cases for useFormik

另外一段 useFormik 的解釋

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.

gracekrcx commented 3 years ago

reset formik value

onSubmit: (values: Values, formikBag: FormikBag) => void | Promise<any>
onSubmit={(values, actions) => {
 setTimeout(() => {
  alert(JSON.stringify(values, null, 2));
  actions.setSubmitting(false);
 }, 1000);
}}

The "FormikBag"