我试图理解为什么combineReducers
在版本1和版本2不起作用时,我将以下的reducers作为参数传递下去:
import {reducers as summaryReducers} from 'package-A';
import {reducers} from 'package-B';
// Version 1
const store = createStore(combineReducers(summaryReducers, reducers));
// Version 2
const store = createStore(combineReducers({summaryReducers, reducers});
reducers
定义为:
const reducers = Object.assign({}, { formState: formReducers });
export { reducers };
summaryReducers
定义为:
const reducers = {popUpManager: popUpManagerReducers};
export { reducers };
问题import
是否将这些reducer作为对象,我们只能将单个对象传递给combineReducers
?
答案 0 :(得分:1)
是的,combineReducers
将一个充满reducer函数的对象作为唯一的参数。
此外,您可能应该更改导出这些reducer函数的方式。如果将它们导出到对象内部,那么当您实际调用combineReducers
时,它会使引用它们变得更加复杂。只需从package-a
和package-b
中导出reducer函数。