Formik 2.0.1 useFormikContext formik值未定义

时间:2019-11-02 07:48:02

标签: formik

useFormikContext中使用Formik 2.0.1。在绑定表单中的formik.values时接收Cannot read property 'values' of undefined

预先感谢!...

Edit react-router useFormikContext

1 个答案:

答案 0 :(得分:1)

您必须像这样在InnerForm()中定义formik:

const InnerForm = () => {
      const formik = useFormikContext<IPerson>()
    return (
      <form>
        <input name="id" value={formik.values.id} />
        <input name="name" value={formik.values.name} />
      </form>
    );
  };