Formik 未捕获类型错误:无法读取未定义的属性“getFieldProps”

问题描述 投票:0回答:3

我正在使用 Formik 创建表单。当我在其中一种表单中使用

FieldArray
时,我收到错误消息
Field.tsx:81 Uncaught TypeError: Cannot read property 'getFieldProps' of undefined

为了验证我是否做错了什么,我从文档中复制了示例并使用了它。不幸的是,文档中的示例不起作用。知道为什么会出错吗?

这是我复制到项目中的示例,但它不起作用:https://formik.org/docs/examples/field-arrays

reactjs formik formik-material-ui
3个回答
3
投票

终于明白了。我收到错误是因为监视模式下的

webpack/typescript
无法正确转译更改。重新启动 webpack 开发服务器解决了问题。


1
投票

我不小心没有将我的视图包装在 Formik 元素内,这导致了同样的错误。我的解决方案是正确包装视图。


0
投票

确保您的组件最终位于 Formik 元素内。

<Formik initialValues={{}} onSubmit={this.handleSubmit}>
    {({ isSubmitting, status, setFieldValue }) => (

         <... your component should be somewhere here ...>
    )}
</Formik>
© www.soinside.com 2019 - 2024. All rights reserved.