使用的时候注意以下几点:

    • 判断是否是在开发环境,只在开发环境添加此调试工具
    • 新建store的时候需要判断window.devToolsExtension值是否存在
    • 使用redux的compose方法结合redux中间件和devToolsExtension
      1. import { createStore, applyMiddleware, compose } from 'redux';
      2. let middlewares = [];
      3. let storeEnhancers;
      4. if(process.env.NODE_ENV==='production'){
      5. storeEnhancers = compose(
      6. applyMiddleware(...middlewares,sagaMiddleware)
      7. );
      8. }else{
      9. storeEnhancers = compose(
      10. applyMiddleware(...middlewares,sagaMiddleware),
      11. (window&& window.devToolsExtension) ? window.devToolsExtension() : (f) => f,
      12. );
      13. }
      14. const store = createStore(reducer, initialState={} ,storeEnhancers);