1
votes

Using useFormikContext in Formik 2.0.1. Receiving Cannot read property 'values' of undefined when binding formik.values in the form.

Thanks in advance!...

Edit react-router useFormikContext

1
see my answerDevFlamur

1 Answers

1
votes

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>
    );
  };