所以说我有以下组件(这是伪代码,但希望以更短的阅读格式说明我的问题)......
class Example extends React.Component {
onChange = () => {
store.dispatch({ type: 'FETCH_VENUE', location: locationValue })
}
render() {
console.log(this.props.id) // "2"
return (
<Field id="salesArea" name="orderHeader.salesArea" type="select" onChange={this.onChange}
component={SelectComponent} />
)
}
}
export default Example;
如果我有一个来自Container组件ExampleContainer的prop,它在this.prop.id中提供了一个值。我如何将其作为locationValue传递,因此基本上相当于
location: this.props.id
没有创建反模式。
this.props.id在HOC中使用formValueSelector来返回salesArea的当前值。
如果我设置位置,我的代码效果很好:例如'2',但有没有办法将道具传递给此调度?
答案 0 :(得分:0)
对于任何偶然发现此事的人。我解决了它如下。
我在简单的Form组件中添加了以下函数。
onVenueChange = (event, venueId) => {
console.log(venueId);
this.props.onVenueChange(venueId)
}
然后我在&lt;中这样称呼它。字段/&gt;
call onChange={this.onVenueChange}
在作为mapDispatch一部分的HOC中,我有以下内容。派出行动。
onVenueChange: venueId => dispatch({type: 'FETCH_EDITABLEORDERS', venueId: venueId })