这是我的减速机工作得很好:
const rootReducer = createStoreWithMiddleware(combineReducers({
companies: companies,
brands: brands,
login: login,
chat: chat,
banners: banners,
sessions: sessions,
settings: settings,
statistics: statistics
}));
我希望我的系统是模块化的,所以我尝试将其更改为:
const rootReducer = createStoreWithMiddleware(combineReducers({
chatModule: {
companies: companies,
brands: brands,
login: login,
chat: chat,
banners: banners,
sessions: sessions,
settings: settings,
statistics: statistics
}
}));
然后我在浏览器中收到此错误:
Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.
这是整个文件代码:
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;
公司,品牌,登录等......出口功能......
答案 0 :(得分:1)
正如错误消息中所述,您应该转到值为 reducers 的combineReducers
对象。您传递了一个值为对象({companies: companies,brands: brands, ...}
)
combineReducers
会返回reducer本身,所以你可以这样做:
const rootReducer = createStoreWithMiddleware(combineReducers({
chatModule: combineReducers({
companies: companies,
brands: brands,
login: login,
chat: chat,
banners: banners,
sessions: sessions,
settings: settings,
statistics: statistics
})
})