gpt4 book ai didi

javascript - redux 形式错误 : Element type is invalid: expected a string or function

转载 作者:行者123 更新时间:2023-11-27 22:53:01 25 4
gpt4 key购买 nike

我正在尝试将redux-form(Ver 5.25)集成到我基于react.js的Web应用程序中,但是我遇到了以下问题:simple sync validation redux-form example :

Uncaught (in promise) Error: Element type is invalid: expected a string 
(for built-in components) or a
class/function (for composite components) but got: undefined.

代码:

<Field name="username" component = {username =>
<div>
<input type="text" {...username} placeholder="Username"/>
{username.touched && username.error && <span>{username.error}</span>}
</div>
}/>

在自定义表单组件(UserRegistrationForm)中,我有以下代码:

export default reduxForm({
form: 'registrationForm',
fields,
validate,
})(UserRegistrationForm);

在我的根 reducer 中,我将 redux-form reducer 安装到表单:

form: formReducer,  // redux-form mounted at 'form'

所以我想知道是什么导致了上面示例代码的错误。我猜是 Field 中的 组件 部分造成的,但我不知道如何修复它。如有任何帮助,我们将不胜感激!

编辑:使用 Field component is here with material-ui 的适当示例,我正在尝试做类似的事情

最佳答案

我认为你做不到

import { Field } from 'redux-form'

似乎不是从该包中导出的。这就是为什么您会收到该异常,因为 Field 未定义。我不确定你想用 redux-form 做什么,我没有看到你在链接的教程中所做的任何事情。

关于javascript - redux 形式错误 : Element type is invalid: expected a string or function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37897608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com