Milan jotva
Milan jotva

Reputation: 143

Redux tool kit error Error: Before running a Saga, you must mount the Saga middleware on the Store using applyMiddleware

I am working with redux toolkit and getting this error, here is my set up for store,

import {  configureStore } from '@reduxjs/toolkit';
import { getDefaultMiddleware } from '@reduxjs/toolkit';
import counterReducer from './SlicesAndReducers';
import createSagaMiddleware from "redux-saga";
import rootSagaToolKit from './Sagas/SagaIndex'
import { applyMiddleware } from 'redux';
const sagaMiddleware = createSagaMiddleware();

const store = configureStore({
  reducer: {
    counter: counterReducer,
    middleware: [...getDefaultMiddleware({ thunk: false }),sagaMiddleware],
  }
});
sagaMiddleware.run(rootSagaToolKit);

export default store;

i already have check Stackoverflow , but haven't found any solution

Upvotes: 1

Views: 1463

Answers (1)

Roy
Roy

Reputation: 118

This line shoule move out of reducer object.. middleware: [...getDefaultMiddleware({ thunk: false }),sagaMiddleware],.. Check my sample below:

import { configureStore } from '@reduxjs/toolkit';
import { persistStore } from 'redux-persist';
import createSagaMiddleware from 'redux-saga';

import persistedReducer from './rootReducer';
import rootSaga from './rootSaga';

const sagaMiddleware = createSagaMiddleware();

export const store = configureStore({
  reducer: persistedReducer,
  middleware: getDefaultMiddleware =>
    getDefaultMiddleware({
      thunk: false,
      immutableCheck: false,
      serializableCheck: false
    }).concat(sagaMiddleware),
  devTools: process.env.NODE_ENV !== 'production'
});

export const persistor = persistStore(store);

sagaMiddleware.run(rootSaga);

Upvotes: 5

Related Questions