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

nro*_*fis 5 redux redux-toolkit

如何从该部分获取完整状态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;
            }
        );
    },
});

Run Code Online (Sandbox Code Playgroud)

我想Foo从Bar动作中操纵切片。但Bar动作有效负载只是该动作的 idBar。

如果我只有 Bar ID,如何Bar从切片中检索实体?Foo有什么办法可以拿到全店吗?