我的react-redux-form中出现错误,我的代码示例与此问题中的内容完全相同,因为我正在按照完全相似的课程学习redux,我在stackoverflow上提到了这个解决方案 Stcakoverflow answer
但是控制台中打印的值未定义。 注意:我使用了第一个解决方案。 这是我的代码。
import React, { Component } from 'react';
import {reduxForm} from 'redux-form';
import {createPost} from '../actions/index.js';
import './postnew.css';
class Postsnew extends React.Component{
handleSubmit(formValues){
//console.log(formValues);
}
render(){
// these are helpers available to us
const {fields:{title,categories,content}}=this.props;
//const {handleSubmit}=this.props;
// const {createPost}=this.props;
// console.log(title);
return(
<form onSubmit={this.handleSubmit(this.props.createPost)}>
<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-submit"> Submit</button>
</form>
);
}
}
//reduxform:1st is form config,2nd is mapstatetoprops,3rd is mapdispatchtoprops
export default reduxForm({
form:'PostsNewForm',
fields:['title','categories','content']
},null,{createPost})(Postsnew);