0
我剛從redux-form:5.3.2
升級到6.0.5
。我修改我的登錄表單,它看起來像這樣:reduxForm似乎沒有將狀態映射到道具
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
成分,但其他大部分eveything是相同的,我的行爲this.props.signinUser
漸漸調用。但是,現在它不存在於this.props
中。降級至5.3.2
繼續工作。我沒有經歷逐漸升級的過程,找出它破裂的地方,如果它壞了,並且假設我沒有做錯什麼。
有什麼建議嗎?
hm ...有趣的reduxForm沒有連接到你的REDX存儲? – lustoykov
它用於但不是在新版本中。 – Gregg