Redux toolkit get access to full state from extra reducers

Viewed 1998

How can I get the full state from the extraReduces section?

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;
            }
        );
    },
});

I want to manipulate the Foo slice from Bar action. But the Bar action payload is just the id of the Bar entity.

How can I retrieve the Bar entity from the Foo slice if I only have the Bar ID? Is there any way to get the full store?

1 Answers
Related