combineReducers没有加载Reducer

时间:2016-06-12 12:08:12

标签: javascript reactjs redux redux-form

有一个问题,在我的index reducer文件中添加reducer并不起作用,但如果我将它添加到store.js文件中的rootReducer对象,一切正常。通过不工作我的意思是我得到一个错误,说明在#34;形式"安装redux-form reducer。

// Index reducer file (Doesn't Work)
import { combineReducers } from 'redux';
import {reducer as  formReducer} from 'redux-form';

const reducers = {
  form: formReducer,  
};

export default combineReducers(reducers);


// Store file (Does work)
import thunkMiddleware from 'redux-thunk';
import { createStore, compose, applyMiddleware, combineReducers } from 'redux';
import reducers from './reducers';
import { routerReducer } from 'react-router-redux';
import actionTypeMiddleware from 'utils/redux/actionTypeMiddleware';

import {reducer as  formReducer} from 'redux-form';

const rootReducer = combineReducers(
  Object.assign(
    {},
    reducers,
    { routing: routerReducer,
      form: formReducer,}
  )
);

const configureStore = (initialState = {}) => {
  const store = compose(
    applyMiddleware(
      actionTypeMiddleware,
      thunkMiddleware
    ),
    window.devToolsExtension ? window.devToolsExtension() : f => f
  )(createStore)(rootReducer, initialState);

  if (module.hot) {
    module.hot.accept(
      './reducers',
      () => {
        const nextReducer = require('./reducers');
        store.replaceReducer(nextReducer);
      }
    );
  }

  return store;
};

const store = configureStore(window.__INITIAL_STATE__ || {});

export default store;

0 个答案:

没有答案