React+Redux - 期望 reducer 是一个函数

React+Redux - Expected the reducer to be a function

我正在尝试在我的通用应用程序中实现 redux,但我在 redux 方面遇到了一些问题。 我有这个 configureStore 函数:

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

export default function configureStore(history, initialState) {
  const reduxRouterMiddleware = routerMiddleware(history);
  let finalCreateStore;

  if (__DEVELOPMENT__ && __CLIENT__ && __DEVTOOLS__) {
    const { persistState } = require('redux-devtools');
    const DevTools = require('../containers/DevTools/DevTools');

    finalCreateStore = compose(
      applyMiddleware(thunkMiddleware)(createStore),
      window.devToolsExtension ? window.devToolsExtension() : DevTools.instrument(),
      persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/))
    )(createStore);
  }
  else {
    finalCreateStore = applyMiddleware(thunkMiddleware)(createStore);
  }

  const store = finalCreateStore(rootReducer, initialState);

  if (__DEVELOPMENT__ && module.hot) {
    module.hot.accept(rootReducer, () => {
      store.replaceReducer(rootReducer);
    });
  }

  return store;
}

然后我的 rootReducer 文件如下所示:

import { combineReducers } from 'redux';
import environment from './environment';
import general from './general';
import alert from './alert';
import user from './user';
import { routerReducer } from 'react-router-redux'


const rootReducer = combineReducers({
  environment,
  general,
  alert,
  user,
  routing: routerReducer
});

export default rootReducer;

问题是我得到了这个错误:预期 reducer 是一个函数。 我在 Whosebug 上进行了 google 和搜索(那里有一些类似的问题),但答案不适用于我的情况。

所以,我做错了什么?为什么?

谢谢。

你试过了吗

import { combineReducers } from 'redux';
import environment from './environment';
import general from './general';
import alert from './alert';
import user from './user'; 
import { routerReducer } from 'react-router-redux'


export const rootReducer = combineReducers({
  environment: environment,
  general: general,
  alert: alert,
  user: user,
 routing: routerReducer
});

export default rootReducer;

试试这个:

finalCreateStore = compose(
    // you write more than one createStore here
    applyMiddleware(thunkMiddleware),
    window.devToolsExtension ? window.devToolsExtension() : DevTools.instrument(),
    persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/))
)(createStore);