Search code examples
reactjsreduxreact-reduxmiddlewareredux-toolkit

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

    // 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


Solution

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