Reputation: 239
this was my reducer that worked great:
const rootReducer = createStoreWithMiddleware(combineReducers({
companies: companies,
brands: brands,
login: login,
chat: chat,
banners: banners,
sessions: sessions,
settings: settings,
statistics: statistics
}));
i want my system to be modular so i tried change it to:
const rootReducer = createStoreWithMiddleware(combineReducers({
chatModule: {
companies: companies,
brands: brands,
login: login,
chat: chat,
banners: banners,
sessions: sessions,
settings: settings,
statistics: statistics
}
}));
then i get this error in the browser:
Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.
this is the whole file code:
import {combineReducers, createStore, applyMiddleware} from 'redux';
import ReduxPromise from 'redux-promise';
import {login, chat, chatClick, banners, sessions, companies, settings, statistics, brands} from '../actions/actions'
const createStoreWithMiddleware = applyMiddleware(ReduxPromise)(createStore);
const rootReducer = createStoreWithMiddleware(combineReducers({
chatModule: {
companies: companies,
brands: brands,
login: login,
chat: chat,
banners: banners,
sessions: sessions,
settings: settings,
statistics: statistics
}
}));
export default rootReducer;
companies, brands, login, etc... are exported function...
Upvotes: 0
Views: 4868
Reputation: 701
As said in error message you should pass to combineReducers
object whose values are reducers. You passed an object whose value is an object ({companies: companies,brands: brands, ...}
)
combineReducers
returns reducer itself so you can do:
const rootReducer = createStoreWithMiddleware(combineReducers({
chatModule: combineReducers({
companies: companies,
brands: brands,
login: login,
chat: chat,
banners: banners,
sessions: sessions,
settings: settings,
statistics: statistics
})
})
Upvotes: 3