flipace / lovli.js

A boilerplate for developing react+redux applications with rethinkdb/horizon as realtime database and express for the server.
MIT License
558 stars 35 forks source link

Reducers in ./reducer/index.js dont work but, in the rootReducer in ./store they do #14

Closed NathHorrigan closed 8 years ago

NathHorrigan commented 8 years ago

Having an issue where the adding a redux-form reducer to my index reducer file doesn't work but if I add it to the rootReducer object in the store.js file, everything works fine.

// 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;
BBB commented 8 years ago

@NathHorrigan Just change export default combineReducers(reducers); to export default reducers;

NathHorrigan commented 8 years ago

Sorry, realised this just after posting the issue and forgot to close it. Thanks Anyway