【发布时间】:2017-10-25 07:46:01
【问题描述】:
我有一个基于Ant Design https://ant.design/components/select/ 的Select 组件的组件
<SomeComponent
onSelect = { this.props.handleSelect }
onDeselect = { this.props.handleDeselect }
selectionList = { valuesList }
value = { values }/>
onSelect 触发动作this.props.handleSelect
export function handleSelect(value) {
return dispatch => {
dispatch(actionCreator(HANDLE_SELECT, value));
}
}
该操作进入reducer
case HANDLE_SELECT: {
const newValues = value_select(state, action);
return {
...state,
find: {
...state.a,
values: newValues
}
}
}
最后,value_select 被调用来完成所有的魔法
export const value_select = function(state, action) {
...
const newData = {
XYZ: action.payload
}
return newData
}
这让我想到了我的问题。
是否可以使用action 进一步发送metadata?想象一下,我多次使用组件<SomeComponent.../>。当onSelect 被触发时,我不知道哪个渲染组件触发了action。
如果我想稍后处理value_select = function(state, action) {... 中的信息,我想知道是哪个component 导致action 正确处理我的数据。我需要在value_select() 中动态设置XYZ,具体取决于哪个<SomeComponent.../> 导致action。 action.payload 只给我保存在value 中<SomeComponent.../> 中的内容,仅此而已。
有没有办法通过onSelect 发送更多信息,或者这是不好的做法,我需要为每个component <SomeComponent.../> 提供action?
【问题讨论】:
标签: javascript reactjs redux antd