【发布时间】:2018-02-25 07:12:59
【问题描述】:
我有一个带有一些 redux 状态的 react 应用程序,如下所示:
{
shape1: {
constraints: {
constraint1: {
key: value
},
constraint2: {
key: value
}
}
},
shape2: {
constraints: {
constraint1: {
key: value
},
constraint2: {
key: value
}
}
}
}
我调度了一个动作并想要删除其中一个约束对象,即。形状 1 的约束 1。这是我的减速器在此操作中的样子,假设我正在尝试从 shape1 中删除约束 1:
case DELETE_CONSTRAINT:
shape = action.payload; // ie. shape1, the parent of the constraint I
// am trying to delete
let {
[shape]: {'constraints':
{'constraint1': deletedItem}
}, ...newState
} = state;
return newState;
这会从状态中删除整个 shape1 对象,而不仅仅是单个约束 1 对象。我哪里出错了/这样做的最佳方法是什么?为了与我的其余代码保持一致,我更喜欢使用对象休息。
谢谢。
【问题讨论】:
标签: reactjs ecmascript-6 redux ecmascript-next