使用handleSubmit将redux表单值返回到state

时间:2017-08-22 20:56:24

标签: reactjs redux-form

我有一个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'})()

0 个答案:

没有答案