【发布时间】:2016-06-18 13:38:50
【问题描述】:
我正在尝试将 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:
form: formReducer, // redux-form mounted at 'form'
所以我想知道是什么导致了上面示例代码的错误。我猜 Field 中的 component 部分导致它,但我不知道如何修复它。任何帮助表示赞赏!
编辑:
使用Fieldcomponent is here with material-ui 的适当示例,我正在尝试做类似的事情
【问题讨论】:
-
<Field>组件声明在哪里? -
有一个导入:
import { Field } from 'redux-form';
标签: javascript forms validation reactjs redux-form