reactjs 警告:reducerPath“cryptoNewsApi”处的RTK查询API的中间件尚未添加到存储

e5njpo68  于 2023-04-05  发布在  React
关注(0)|答案(1)|浏览(86)

我已经用redux创建了两个API组件,然后我想在商店中调用它们,这是我写的代码

import { configureStore} from "@reduxjs/toolkit";
import {cryptoApi} from '../services/cryptoApi';
import {cryptoNewsApi} from '../services/cryptoNewsApi'
export default configureStore({
    reducer: {
        [cryptoApi.reducerPath]: cryptoApi.reducer,
        [cryptoNewsApi.reducerPath]: cryptoNewsApi.reducer,
    },
    middleware: (getDefaultMiddleware) =>
        getDefaultMiddleware().concat(cryptoApi.middleware),

    // middleware: (getDefaultMiddleware) =>
    //     getDefaultMiddleware().concat(cryptoNewsApi.middleware),

});

它没有工作,所以我意识到我应该添加cryptoNewsApi到中间件太我怎么能做到这一点

62lalag4

62lalag41#

Do this

import { configureStore } from "@reduxjs/toolkit";
import { cryptoApi } from "../services/cryptoApi";
import { CryptoNewsApi } from "../services/CryptoNewsApi";

export const store = configureStore({
    reducer: {
    [cryptoApi.reducerPath]: cryptoApi.reducer,
    [CryptoNewsApi.reducerPath]: CryptoNewsApi.reducer
},
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(
    cryptoApi.middleware,
    CryptoNewsApi.middleware
)
})

相关问题