Redux工具包可以从额外的减速器访问完整状态



如何从extraReduces部分获得完整状态?

createSlice({
name: 'foos',
initialState: {
foos: [],
},
reducers: {},
extraReducers: builder => {
builder.addCase(
barAction,
(state, action) => {
const barId = action.payload.id; // barAction handler, the payload is the bar's id
const bar = ??? // getStore().bars[barId]
state.foo[bar.fooId].baz = true;
}
);
},
});

我想从Bar操作操作Foo切片。但是Bar动作有效载荷只是Bar实体的id。

如果我只有Bar ID,如何从Foo切片中检索Bar实体?有什么办法可以把商店弄满吗?

根据定义,Redux切片缩减器只能访问自己的状态切片。

然而,我们确实鼓励多个减速器对同一调度行动作出响应。

最新更新