我有一个reduxForm,它使用formValueSelector来收集表单值。我想将这些值推入空状态以与方法一起使用。
state = {
employmentHistory: [],
}
handleChange = (formValues) => {
const { employmentHistory } = this.state;
employmentHistory.push(formValues);
this.setState({
employmentHistory,
}, () => {
if (employmentHistory.length > 0) {
this.props.whenUserCompletedQuestion({
employmentHistory,
});
} else {
this.props.whenUserCompletedQuestion({
employmentHistory: null,
});
}
});
console.log(employmentHistory);
}
这是表格:
<form onChange={this.handleChange}>
<FieldArray
name="employmentHistory"
component={someComponent}
roles={translatedTypes(roles, 'vehicleTypes')}
dispatch={more.dispatch}
driverProfile={driverProfile}
change={more.change}
profileReminder
/>
</form>
这是redux connect:
const selector = formValueSelector('employmentHistory');
export default connect(
(state) => ({
initialValues: {
employmentHistory: state.driver.employmentHistory,
...pickInitialValues(state.driver.driverProfile),
},
formValues: getFormValues('employmentHistory')(state),
})
)(reduxForm({
form: 'employmentHistory'})()