首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >警告: reducerPath " API“上的RTK-Query api中间件尚未添加到存储区中。

警告: reducerPath " API“上的RTK-Query api中间件尚未添加到存储区中。
EN

Stack Overflow用户
提问于 2022-02-24 08:53:52
回答 1查看 1.3K关注 0票数 1

我正在尝试向已经使用RTK查询的商店添加一个自定义中间件。但是我得到了“警告: reducerPath上的reducerPath中间件”还没有添加到商店中。运行时出错,尽管我确实添加了api中间件。这是我的store.ts文件:

代码语言:javascript
复制
import { combineReducers, configureStore } from '@reduxjs/toolkit'
import { apiSlice } from './apiSlice'
import { homeModeReducer, workingReducer, bannersReducer, latestEventDataReducer } from './reducers/reducers'
import { useDispatch, useSelector, TypedUseSelectorHook } from 'react-redux'
import { latestMiddleware } from './middleware'

const reducer = combineReducers({
    [apiSlice.reducerPath]: apiSlice.reducer,
    mode: homeModeReducer,
    working: workingReducer,
    banners: bannersReducer,
    latestEventData: latestEventDataReducer
})

const store = configureStore({
    reducer,
    middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(latestMiddleware).concat(apiSlice.middleware)
})

export default store
export type RootState = ReturnType<typeof reducer>;
export type AppDispatch = typeof store.dispatch
export const useAppDispatch = () => useDispatch<AppDispatch>()
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector

我的中间件被定义为:

代码语言:javascript
复制
import { Middleware } from 'redux'
import { RootState } from './store'

export const latestMiddleware: Middleware<
    {}, // Most middleware do not modify the dispatch return value
    RootState
> = storeApi => next => action => {
    console.log(action.type)
    return storeApi.getState() // correctly typed as RootState
}

它编译正确,但在运行时失败。有什么帮助吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-24 09:33:06

您的latestMiddleware没有调用next(action),这意味着下一个中间件(以及最后一个简化器)将永远不会被执行。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71249368

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档