相关疑难解决方法(0)

Redux 工具包:是否有两个切片在 extraReducers 中互相引用彼此的操作?

我希望两个不同的切片能够交叉引用彼此的操作,如下所示:

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
        },
    },
});
Run Code Online (Sandbox Code Playgroud)

问题是我在尝试为 sliceA 设置 extraReducers 时收到 sliceB 未定义的错误。

为了清楚起见,我想将切片分开,但它们的某些操作会相互影响。

实现这一目标的好方法是什么?

redux-toolkit

7
推荐指数
1
解决办法
5062
查看次数

标签 统计

redux-toolkit ×1