I would like two different slices to cross-reference each other's actions like so:
const sliceA = createSlice({
name: "sliceA",
initialState: null,
reducers: {
someReducer: (state, action) => {
// do something
},
},
extraReducers: {
[sliceB.actions.anotherReducer]: (state, action) => {
// do something
},
},
});
const sliceB = createSlice({
name: "sliceB",
initialState: null,
reducers: {
anotherReducer: (state, action) => {
// do something else
},
},
extraReducers: {
[sliceA.actions.someReducer]: (state, action) => {
// do something else
},
},
});
The problem is that I receive the error that sliceB is undefined when trying to set the extraReducers for sliceA.
I would like to keep the slices separate for clarity, but that some of their actions affect each other.
What is a good way to achieve that?