你如何将道具传递给 Redux-Form 中的 onChange 函数?
How do you pass a prop to an onChange function in Redux-Form?
假设我有以下组件(这是伪代码,但希望能以更短的阅读格式说明我的问题)...
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;
如果我有一个来自容器组件 ExampleContainer 的道具,它在 this.prop.id 处提供了一个值。我怎样才能将它作为 locationValue 传递,所以基本上相当于
location: this.props.id
没有创建反模式。
this.props.id 在 HOC 中使用 formValueSelector 来 return salesArea 的当前值。
例如,如果我设置 location: '2',我的代码工作得很好,但是有没有办法将 prop 传递到这个 dispatch 中?
对于偶然发现此问题的任何人。我是这样解决的
我在简单的Form组件中添加了如下功能
onVenueChange = (event, venueId) => {
console.log(venueId);
this.props.onVenueChange(venueId)
}
然后我在 中这样称呼它
call onChange={this.onVenueChange}
在作为 mapDispatch 一部分的 HOC 中,我有以下内容。调度动作。
onVenueChange: venueId => dispatch({type: 'FETCH_EDITABLEORDERS', venueId: venueId })
假设我有以下组件(这是伪代码,但希望能以更短的阅读格式说明我的问题)...
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;
如果我有一个来自容器组件 ExampleContainer 的道具,它在 this.prop.id 处提供了一个值。我怎样才能将它作为 locationValue 传递,所以基本上相当于
location: this.props.id
没有创建反模式。
this.props.id 在 HOC 中使用 formValueSelector 来 return salesArea 的当前值。
例如,如果我设置 location: '2',我的代码工作得很好,但是有没有办法将 prop 传递到这个 dispatch 中?
对于偶然发现此问题的任何人。我是这样解决的
我在简单的Form组件中添加了如下功能
onVenueChange = (event, venueId) => {
console.log(venueId);
this.props.onVenueChange(venueId)
}
然后我在
call onChange={this.onVenueChange}
在作为 mapDispatch 一部分的 HOC 中,我有以下内容。调度动作。
onVenueChange: venueId => dispatch({type: 'FETCH_EDITABLEORDERS', venueId: venueId })