redux-form错误:元素类型无效:期望字符串或函数

时间:2016-06-18 13:38:51

标签: javascript forms validation reactjs redux-form

我正在尝试将redux-form (Ver 5.25)集成到基于react.js的网络应用中,但我遇到了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);

在我的root reducer中,我将redux-form reducer安装到 form

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

所以我想知道上面的示例代码导致错误的原因。我猜 Field 中的组件部分正在导致它,但我不知道如何修复它。任何帮助表示赞赏!

修改 使用Field component is here with material-ui的适当示例,我尝试做类似的事情

1 个答案:

答案 0 :(得分:1)

我认为你不能做到

import { Field } from 'redux-form'

似乎不是从该包导出的。这就是为什么你得到那个例外,因为Field未定义。我不确定你要用redux-form做什么,我没有看到你在链接教程中所做的事情。