我刚刚从realcoprime
升级到redux-form:5.3.2
。我修改了我的签到形式,它看起来像这样:
6.0.5
在升级之前,我没有使用import React, { Component } from 'react';
import { Field, reduxForm } from 'redux-form';
import * as actions from '../actions/authActions';
class SignIn extends Component {
handleFormSubmit({ email, password }) {
console.log(this.props);
this.props.signinUser({ email, password }, this.props.location);
}
renderAlert() {
if (this.props.errorMessage) {
return (
<div className="alert alert-danger">
{this.props.errorMessage}
</div>
);
} else if (this.props.location.query.error) {
return (
<div className="alert alert-danger">
Authorization required!
</div>
);
}
}
render() {
const { message, handleSubmit } = this.props;
const renderField = ({input, label, type, meta: { touched, error } }) => (
<fieldset className="form-group">
<label>{label}</label>
<input {...input} className="form-control" />
</fieldset>
)
return (
<form onSubmit={handleSubmit(this.handleFormSubmit.bind(this))}>
{this.renderAlert()}
<Field name="username" type="text" component={renderField} label="Username"/>
<Field name="password" type="password" component={renderField} label="Password"/>
<button action="submit" className="btn btn-primary">Sign In</button>
</form>
);
}
}
function mapStateToProps(state) {
return { errorMessage: state.auth.error }
}
export default reduxForm({
form: 'signin',
fields: ['email', 'password']
}, mapStateToProps, actions)(SignIn)
组件,但大多数其他组件都是相同的,我的操作Field
被调用。但是,现在它在this.props.signinUser
中不存在。降级至this.props
继续有效。我没有经历过逐步升级的过程,如果它破裂了,并且假设我没有做错事,那就找到它。
有什么建议吗?
答案 0 :(得分:0)
而且......我刚刚找到了答案。我不得不改变这个:
export default reduxForm({
form: 'signin',
fields: ['email', 'password']
}, mapStateToProps, actions)(SignIn)
到此:
SignIn = reduxForm({
form: 'signin',
fields: ['email', 'password']
})(SignIn);
export default connect(mapStateToProps, actions)(SignIn);
这似乎不在文档中,但它应该是。