Formik 2.0.1 useFormikContext formik values undefined

梦想与她 提交于 2021-01-28 07:35:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!