问题
Using useFormikContext
in Formik 2.0.1
. Receiving Cannot read property 'values' of undefined
when binding formik.values in the form.
Thanks in advance!...
回答1:
You have to define formik inside the InnerForm() like this:
const InnerForm = () => {
const formik = useFormikContext<IPerson>()
return (
<form>
<input name="id" value={formik.values.id} />
<input name="name" value={formik.values.name} />
</form>
);
};
来源:https://stackoverflow.com/questions/58669214/formik-2-0-1-useformikcontext-formik-values-undefined