redux devtools Uncaught Error:操作必须是普通对象。使用自定义中间件进行异步操作

时间:2016-07-20 06:54:56

标签: redux react-redux redux-devtools

这是我创建商店的方式

import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import { routerMiddleware } from 'react-router-redux';
import rootReducer from '../reducers';

const debugware = [];
if (process.env.NODE_ENV !== 'production') {
  const createLogger = require('redux-logger');
  debugware.push(createLogger({
    collapsed: true
  }));
}

export default function configureStore(history, initialState) {
  const store = createStore(
    rootReducer,
    initialState,
    window.devToolsExtension ? window.devToolsExtension() : f => f,
    applyMiddleware(thunkMiddleware, routerMiddleware(history), ...debugware),
  );

  if (module.hot) {
    // Enable Webpack hot module replacement for reducers
    module.hot.accept('../reducers', () => {
      const nextRootReducer = require('../reducers/index').default;
      store.replaceReducer(nextRootReducer);
    });
  }

  return store;
}

但我的应用程序停止工作,我可以找到原因。有任何建议请。

2 个答案:

答案 0 :(得分:4)

你可以试试这个:

import { createStore, applyMiddleware, compose } from 'redux';

const store = createStore(
  rootReducer,
  initialState, 
  compose(
    applyMiddleware(thunkMiddleware, routerMiddleware(history), ...debugware),
    window.devToolsExtension ? window.devToolsExtension() : f => f
  )
);

答案 1 :(得分:1)

DevTools的增强器应该始终是最后的组合,因此它将了解其他中间件和增强器。

此外,如果您想远程调度操作,还应添加:

if (window.devToolsExtension) window.devToolsExtension.updateStore(store)

troubleshooting所述。