1
単一の入力値を取得してログに記録しようとしています。これは、既存の名前値propを持つ編集フォームです。redux-formとformValueSelectorで入力フォーム値を取得する方法
何らかの理由でフィールド入力の値で状態 '名前'を設定しません。私は自分の問題だと思う接続部分をどのように構造化するのか分かりません。特に、非フォーム状態とフォーム状態の両方を含むようにmapStateToPropsを書く方法については明確ではありません。
部分的に縮小コード:
import { Field, reduxForm, formValueSelector } from 'redux-form';
import { connect } from 'react-redux';
import { updateStable } from '../../actions/index';
const selector = formValueSelector('myEditForm');
class EditStuff extends Component {
constructor(props) {
super(props);
this.state = {
name: this.props.name
};
}
componentDidMount() {
this.props.initialize({
name: this.props.name || ''
});
}
componentDidUpdate() {
// this.state.name is not getting set from input value
this.props.updateLocalActiveStuffData(this.state.name);
}
render() {
const { handleSubmit } = this.props;
return (
<div>
<form onSubmit={handleSubmit(this.onSubmit.bind(this))}>
<Field
label="Name"
name="name"
class="name"
type="text"
component={renderField}
/>
<button type="submit" className="btn btn-primary">
Submit
</button>
</form>
</div>
</div>
);
}
}
function mapStateToProps(state) {
return {
displayEditForm: state.displayEditForm, //my own non-form related state
name: selector(state, 'name') //form input 'name'
};
}
export default connect(mapStateToProps, { updateStuff })(
reduxForm({
form: 'myEditForm'
})(EditStuff)
);
フォーム名の違いは、コピー/ペーストタイプミス-I編集した質問だった役立つことを願って。私はあなたの推奨するinitialValuesの設定方法をチェックします。 –