0

有一个问题,在我的 index reducer 文件中添加 reducer 不起作用,但如果我将它添加到 store.js 文件中的 rootReducer 对象,一切正常。通过不工作,我的意思是我收到一个错误,指出将 redux-form reducer 安装在“form”处。

// 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;
4

0 回答 0