Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reducer is not a function #40

Closed
sarink opened this issue Aug 12, 2016 · 1 comment
Closed

reducer is not a function #40

sarink opened this issue Aug 12, 2016 · 1 comment

Comments

@sarink
Copy link

sarink commented Aug 12, 2016

I keep running into the error reducer is not a function.

Not sure what I'm doing wrong? My state is a plain object and some of the keys within state are Immutable

redux/modules/rootReducer.js:

import { combineReducers } from 'redux-immutable';
import { routeReducer } from './routeReducer';

export default combineReducers({
  routing: routeReducer,
});

redux/modules/routeReducer.js:

import Immutable from 'immutable';
import { LOCATION_CHANGE } from 'react-router-redux';

const initialState = Immutable.fromJS({
  locationBeforeTransitions: null
});

const locationChangeReducer = (state, action) => {
  return Object.assign({}, state, {locationBeforeTransitions: action.payload});
};

export default function routeReducer(state = initialState, action) {
  switch (action.type) {
    case LOCATION_CHANGE: return locationChangeReducer(state, action);
    default: return state;
  }
}

redux/createStore.js:

import { createStore as _createStore, applyMiddleware, compose } from 'redux';
import createMiddleware from './middleware/clientMiddleware';
import { routerMiddleware } from 'react-router-redux';
import reducer from './modules/reducer';
import { persistState } from 'redux-devtools';
import { DevTools } from 'containers';

export default function createStore(history, client, data) {
  // Sync dispatched route actions to the history
  const reduxRouterMiddleware = routerMiddleware(history);

  const middleware = [createMiddleware(client), reduxRouterMiddleware];

  let finalCreateStore;
  if (_DEVELOPMENT__ && __CLIENT__ && __DEVTOOLS__) {
    finalCreateStore = compose(
      applyMiddleware(...middleware),
      window.devToolsExtension ? window.devToolsExtension() : DevTools.instrument(),
      persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/))
    )(_createStore);
  } else {
    finalCreateStore = applyMiddleware(...middleware)(_createStore);
  }

  const store = finalCreateStore(reducer, data);

  if (__DEVELOPMENT__ && module.hot) {
    module.hot.accept('./modules/reducer', () => {
      store.replaceReducer(reducer);
    });
  }

  return store;
}
@gajus
Copy link
Owner

gajus commented Aug 13, 2016

Duplicate of #38

@gajus gajus closed this as completed Aug 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants