Redux-Toolkit & RTK Query, reducers of slices are not being added to the root state

Viewed 411

I began to use RTK query and I want to use RTK Query along with other redux utilities like createSlice. What I am struggling with is that only the createApi's reducer state is showing on the Redux Devtools extension, state for the reducers of the other slice is not showing.

/* eslint-disable @typescript-eslint/no-explicit-any */
import { AnyAction, configureStore, Dispatch, Middleware } from '@reduxjs/toolkit';
import logger from 'redux-logger';
import ApiService from '../services/api.service';

import authReducer from './authSlice';

const middleware: Middleware<any, any, Dispatch<AnyAction>>[] = [];

if (process.env.NODE_ENV === 'development') {
  middleware.push(logger);
}

const store = configureStore({
  reducer: {
    auth: authReducer,
    [ApiService.reducerPath]: ApiService.reducer,
  },
  middleware: getDefaultMiddleware => getDefaultMiddleware().concat(logger).concat(ApiService.middleware),
  devTools: process.env.NODE_ENV === 'development',
});

export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;

export default store;



import { createApi } from '@reduxjs/toolkit/query/react';
import { baseQueryWithReauth } from '../utils';

export enum RequestMethods {
  GET = 'GET',
  POST = 'POST',
  PATCH = 'PATCH',
  DELETE = 'DELETE',
}

const ApiService = createApi({
  baseQuery: baseQueryWithReauth,
  reducerPath: 'api',
  tagTypes: ['Space'],
  endpoints: () => ({}),
});

export default ApiService;

I other words, I am expecting both API and auth to show up inside my redux state object but only the API state is appearing (from createApi).

0 Answers
Related