首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么redux-form抛出错误?

为什么redux-form抛出错误?
EN

Stack Overflow用户
提问于 2017-02-16 11:54:13
回答 2查看 454关注 0票数 1

我正在尝试实现redux-form,但我遇到了一个错误,似乎无法修复它或找到正确的解决方案。错误:React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.

代码语言:javascript
复制
import { Form, reduxForm } from 'redux-form';


    LocationInput({input, meta: { touched, error }, ...custom}) {
    return (
      <div>
        <input placeholder="Location..." type="text" />
      </div>
    );
  }

  render() {

    return (
      <Form name="locationInput" component={this.LocationInput} />
    )

 }
EN

回答 2

Stack Overflow用户

发布于 2017-02-16 13:58:42

您需要创建一个表单组件并使用redux-form装饰器导出formComponent

代码语言:javascript
复制
export default reduxForm({
  form: 'formName'  // a unique identifier for this form
})(formComponent)
票数 1
EN

Stack Overflow用户

发布于 2017-02-17 01:55:34

您不应该使用Form,除非您正在通过操作分派进行一些花哨的提交。更多地查看示例。

您需要定义一个表单组件,用reduxForm()装饰它,然后在其中放入一些<Field>元素。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42264608

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档