如何使用Redux Saga运行Redux DevTools?

bie*_*ier 3 redux redux-saga react-redux

尝试使用redux saga运行reduxdevtools:

收到此错误:

Error
Before running a Saga, you must mount the Saga middleware on the Store using applyMiddleware
Run Code Online (Sandbox Code Playgroud)

这是我的jscode:

const store = createStore(
  reducer,
  applyMiddleware(sagaMiddleware),
  window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);
Run Code Online (Sandbox Code Playgroud)

如何使用saga运行此devtool?或者,否则会起作用吗? 码笔

Yur*_*lov 7

上一个答案(由 trkaplan 提供)使用来自“redux-devtools-extension”包的导入方法 composeWithDevTools。如果你不想安装这个包,你可以使用这个代码(基于文档):

      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);
Run Code Online (Sandbox Code Playgroud)


trk*_*lan 5

我用终极版-devtools扩展包这里所描述的,终极版-devtools扩展文档

添加软件包后,我将商店定义替换为:

const store = createStore(
  reducer,
  composeWithDevTools(
    applyMiddleware(sagaMiddleware)
  )
);
Run Code Online (Sandbox Code Playgroud)

固定码笔链接