给出一个如下所示的状态树:
machines:{
"first_machine" : {},
"second_machine" : {options:[], packages[]},
}
如何将“选项”和“包”分配给Reducer中的给定“机器名”(状态树中存在所有机器名,我只需要访问其键与payload.machineName匹配的那个)并分配给它)? 这是动作创建者:
export const submitconfigMachine = (machineName, options, packages) =>({
type: CONFIG_MACHINE,
payload: {machineName, options, packages}
});
答案 0 :(得分:1)
const { machineName, ...data } = action.payload;
return {
...state,
machines: {
...state.machines,
[machineName]: data,
},
};