使用import作为combineReducers传递参数

时间:2017-09-07 15:37:49

标签: javascript redux react-redux

我试图理解为什么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

1 个答案:

答案 0 :(得分:1)

是的,combineReducers将一个充满reducer函数的对象作为唯一的参数。

此外,您可能应该更改导出这些reducer函数的方式。如果将它们导出到对象内部,那么当您实际调用combineReducers时,它会使引用它们变得更加复杂。只需从package-apackage-b中导出reducer函数。