A
A
Alexander2021-08-25 22:48:16
redux
Alexander, 2021-08-25 22:48:16

How to add redux saga to redux toolkit?

Please tell me if I'm doing it right?

import { configureStore } from '@reduxjs/toolkit'
import { rootReducer } from './rootReducer'
import createSagaMiddleware from 'redux-saga'

const sagaMiddleware = createSagaMiddleware()

export const store = configureStore({
  reducer: rootReducer,
  middleware: (getDefaultMiddleware) =>
  getDefaultMiddleware({
    thunk: false,
    serializableCheck: false,
  }).concat(sagaMiddleware),
})

I will be grateful for the answer

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
abberati, 2021-08-25
@abberati

Works? So right. Does not work? What doesn't work?
There must be a .run() somewhere else, if my memory serves me.

T
Tatyana Dzhanaeva, 2021-11-12
@DjanTanKa

and why thunk: false? like because thunk is under the hood of the toolkit?

D
Dmitrii_Kechin, 2022-04-22
@Dmitrii_Kechin

I did this:

export const setupStore = () => {
  const sagaMiddleware = createSagaMiddleware();
  
  const store = configureStore({
    reducer: rootReducer,
    middleware: (getDefaultMiddleware) =>
      getDefaultMiddleware({ thunk: false }).concat(sagaMiddleware),
  });
  sagaMiddleware.run(rootWatcher);

  return store;
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question