根据定义,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
实体?有什么办法可以把商店弄满吗?
然而,我们确实鼓励多个减速器对同一调度行动作出响应。