为什么React Redux Form,没有为SELECT选项传递formState?

时间:2017-08-04 20:17:55

标签: reactjs redux react-redux react-redux-form

以下是相关的代码段。我正在使用redux表单来渲染选择字段...当字段呈现时,当您更改选择选项时,表单的状态永远不会更改...

console.log(this.props.formState)

以上总是呈现为未定义......我做错了什么?感谢

let SelectGroup = ({input, title, label, type, defaultOption, options, meta: {touched, error, pristine}}) =>
    <select>
      {options.map(o =>
        <option key={o.id} value={o.id}>{o.title}</option>
      )}
    </select>
render() {
   console.log(this.props.formState)

    ....
        <Field
          component={ SelectGroup }
          name={ 'industry_id' }
          title={ 'industry_id' }
          options={ this.props.industries }
        />

  }
}



PlacePage = reduxForm({
  form: 'PlacePageForm',
  validate,
})(PlacePage);

const selector = formValueSelector('PlacePageForm')

const mapStateToProps = state => {
  return {
    formState: getFormValues('PlacePageForm')(state),
    selected_industry_id: selector(state, 'industry_id'),
    ....
  };
};




export default connect(mapStateToProps)(PlacePage);

1 个答案:

答案 0 :(得分:0)

通过改变问题解决了这个问题:

<select>

为:

<select {...input}>