【发布时间】:2017-03-15 09:29:36
【问题描述】:
我在使用 redux-form
时遇到错误控制台中的错误消息:
- bundle.js:32511 未捕获的错误:您必须通过 handleSubmit() 一个 onSubmit 函数或将 onSubmit 作为 prop(...) 传递
上述错误出现在页面加载和按钮点击
请参考以下导致控制台错误的代码示例。
import React, { Component } from 'react';
import { reduxForm } from 'redux-form';
import { createPost } from '../actions/index';
class PostsNew extends Component {
render() {
const { fields: { title, categories, content }, handleSubmit } = this.props;
return (
<form onSubmit={handleSubmit(this.props.createPost)}>
<h3>Create a new Post</h3>
<div className="form-group">
<label>Title</label>
<input type="text" className="form-control" {...title}/>
</div>
<div className="form-group">
<label>Categories</label>
<input type="text" className="form-control" {...categories}/>
</div>
<div className="form-group">
<label>Content</label>
<textarea className="form-control" {...content}/>
</div>
<button type="submit" className="btn btn-primary">Submit</button>
</form>
);
}
}
export default reduxForm({
form: 'PostsNewForm',
fields: ['title', 'categories', 'content']
}, null, { createPost })(PostsNew);
这是 StephenGrider redux 教程
的一步一步的跟随
提前谢谢:)
【问题讨论】:
-
你是如何调用 PostsNew 组件的?
-
PostsNew 在路由中被调用
路线>
标签: reactjs redux redux-form