警告: 未将 reducerPath 为 “cryptoNewsApi” 的 RTK-Query API 中间件添加到存储中。

huangapple go评论72阅读模式
英文:

Warning: Middleware for RTK-Query API at reducerPath "cryptoNewsApi" has not been added to the store

问题

I have created two Api components with redux and then I want to call them both in the store and this is the code I've written

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),
});

and it didn't work
so I recognized that I should add the cryptoNewsApi to the middleware too
How can I do this?

英文:

I have created two Api components with redux and then I want to call them both in the store and this is the code I've written

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),

});

and it didn't work
so I recognized that I should add the cryptoNewsApi to the middleware too
How can I do this

答案1

得分: 2

做如下更改:

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
    )
})
英文:

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
    )
})

huangapple
  • 本文由 发表于 2023年2月9日 02:34:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75390288.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定