【发布时间】:2021-11-22 14:50:00
【问题描述】:
我有以下代码:
export const walkSlice = createSlice({
name: "walk"
, initialState
, reducers: {}
,extraReducers: (builder) => {
builder
// Change status to loading when API call is pending
.addCase(fetchWalk.pending, (state) => {
state.status = cStatusType.Loading;
})
...
当 reducers 设置为空对象时,切片似乎不会出现在 Redux 状态。我只想使用extraReducers 来处理API 调用。我已经测试过添加一个空的减速器,例如。
reducers: {
add: (state) => {
},
...
这似乎将切片添加到状态。有没有解决的办法?如果可能,我不想要不必要的代码。
【问题讨论】:
标签: reactjs redux react-redux redux-toolkit