Redux 工具包从额外的 reducer 获取完整状态

Redux toolkit get access to full state from extra reducers

如何从 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 slice reducers only have access to their own slice of the state,根据定义。

但是,我们确实鼓励 multiple reducers responding to the same dispatched action