我想要两个不同的切片来交叉引用彼此的操作,如下所示:
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
},
},
});
问题是我在尝试为 sliceA 设置 extraReducers 时收到未定义 sliceB 的错误。
为了清楚起见,我想将切片分开,但它们的某些操作会相互影响。
实现这一目标的好方法是什么?