英文:
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
)
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论