【问题标题】:Getting 'CategoryNewForm' is not defined no-undef while working with redux-form在使用 redux-form 时,获取“CategoryNewForm”未定义为 no-undef
【发布时间】:2017-12-11 16:44:49
【问题描述】:

我目前正在学习 redux-react 并开发一个简单的应用程序。 我想在我的应用程序中使用 redux-form。在我的组件中,我有以下代码

组件/AddNewCategory.jsx:

import React, { Component } from 'react';
import { reduxForm } from 'redux-form';

class CategoryNew extends Component {
    render() {
        const { fields: { title, desc }, handleSubmit } = this.props;
        console.log(title);

        return (
            <form onSubmit={handleSubmit}>
                <h3>Create A New Category</h3>
                <div className="form-group">
                    <label>title: </label>
                    <input type="text" className="form-control" />
                </div>  
                <div className="form-group">
                    <label>Description: </label>
                    <input type="text" className="form-control" />
                </div>  
                <button type="submit" className="btn btn-primary">Submit</button>
            </form>         
        );
    }
}
export default reduxForm({
    form: CategoryNewForm,
    fields: ['title', 'desc']   
})(CategoryNew);

当我运行应用程序时,我收到以下错误: ./src/app/admin/components/add_new_category/AddNewCategory.jsx 第 28 行:'CategoryNewForm' 未定义 no-undef 搜索关键字以了解有关每个错误的更多信息。

请建议我如何解决此错误。提前致谢。

【问题讨论】:

    标签: react-redux redux-form


    【解决方案1】:
    export default reduxForm({
        form: 'CategoryNewForm',
        fields: ['title', 'desc']   
    })(CategoryNew);
    

    表单名称应该是字符串

    【讨论】:

      猜你喜欢
      • 2019-10-05
      • 2021-10-16
      • 2018-06-09
      • 2018-10-02
      • 2021-05-26
      • 2021-06-17
      • 2022-01-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多