bier hier
bier hier

Reputation: 22540

How to run redux devtools with redux saga?

Trying to run reduxdevtools with redux saga:

Getting this error:

Error
Before running a Saga, you must mount the Saga middleware on the Store using applyMiddleware

This is my jscode:

const store = createStore(
  reducer,
  applyMiddleware(sagaMiddleware),
  window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);

How can I run this devtool with saga? Alternatively what would work otherwise? codepen

Upvotes: 16

Views: 9403

Answers (4)

Ericgit
Ericgit

Reputation: 7073

This is how you configure your redux, redux-devtool-extension and redux-saga for the real projects..

import { createStore, applyMiddleware } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import createSagaMiddleware from 'redux-saga';

import rootReducer from '../reducers';
import rootSaga from '../sagas';

const configureStore = () => {
    const sagaMiddleware = createSagaMiddleware();
    return {
        ...createStore(rootReducer, composeWithDevTools(applyMiddleware(sagaMiddleware))),
        runSaga: sagaMiddleware.run(rootSaga),
    };
};

export default configureStore;

Upvotes: 2

keerthi gowda
keerthi gowda

Reputation: 11

Incase Compose of Redux is used. Then below code is useful. Step 1: Add chrome Redux DevTools extension. step 2: npm install redux-devtools-extension.

    import { composeWithDevTools } from 'redux-devtools-extension';
    const store = createStore(
                  reducer,
                  compose(
                  applyMiddleware(sagaMiddleware),
                  composeWithDevTools(),
                  ),
                  );

Upvotes: 1

Yury Kozlov
Yury Kozlov

Reputation: 1381

The previous answer (by trkaplan) uses an imported method composeWithDevTools from 'redux-devtools-extension' package. If you don't want to install this package, you may use this code (based on the docs):

      const composeEnhancers =  typeof window === 'object' && window['__REDUX_DEVTOOLS_EXTENSION_COMPOSE__'] ? 
      window['__REDUX_DEVTOOLS_EXTENSION_COMPOSE__']({ }) : compose;
      const enhancer = composeEnhancers(
        applyMiddleware(thunkMiddleware, sagaMiddleware, /*other middleware*/),
        /* other store enhancers if any */
      );
      const emptyReducer = () => {};
      const store = createStore(emptyReducer, enhancer);

Upvotes: 11

trkaplan
trkaplan

Reputation: 3487

I've used redux-devtools-extension package as described here, redux-devtools-extension documentation.

After adding the package, I've replaced the store definition with this:

const store = createStore(
  reducer,
  composeWithDevTools(
    applyMiddleware(sagaMiddleware)
  )
);

Fixed Codepen Link

Upvotes: 23

Related Questions