redux工具箱中的extraReducers没有捕捉到动作


import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
import request from '../../utils/request';
export const fetchReports = createAsyncThunk(
'reports/fetchReports',
async (Criteria, thunkAPI) => {
const url = '/fetchReport';
const options = { method: 'POST', data: { Criteria: { ...Criteria } } };
const response = await request(url, options);
return response.ReportData;
},
);
export const clinicReportsSlice = createSlice({
name: 'reports',
initialState: {
reports: {}
},
reducers: {
},
extraReducers: {
[fetchReports.fulfilled]: (state, action) => {
console.log("INFO: Action Called!!") ---------------> not able to see this log
},
},
});
export default clinicReportsSlice.reducer;

所以,我能够看到动作";reports/fetchReports/complemented";在devtools内部调用。但对我来说不幸的是,在extraReducers 中没有任何效果

我甚至尝试过对动作名称进行编码,这显然不会有任何区别。但我还是试过了。

'reports/fetchReports/fulfilled': () => {
console.log('asdf');
},

你能想出它不起作用的可能原因吗?

我的配置是这样的,它是现有代码在没有任何错误的情况下工作所必需的。

export const store = configureStore({
reducer: allReducers,
middleware: (getDefaultMiddleware) => {
console.log(getDefaultMiddleware().concat(apiMiddleware));
return [getDefaultMiddleware()[1], apiMiddleware];
},
});

当存在具有相同typePrefix的重复异步链接时,我遇到了这个问题。

你能确认没有其他异步链接使用相同的操作类型吗;reports/fetchReports";?

相关内容

  • 没有找到相关文章

最新更新