0
下面是一個相關的代碼片段。我使用的是終極版的形式來呈現一個選擇字段...當現場呈現,當你改變選擇選項,表格的狀態沒有改變...爲什麼React Redux Form沒有爲SELECT選項傳遞formState?
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);
很難從例子說,但如果你要設置自己的自定義組件,通它到' '組件比你負責實現輸入鉤子。以下是來自於redux-form文檔的常見問題解答信息:http://redux-form.com/6.6.3/docs/faq/CustomComponent.md/ –
ryandrewjohnson