React-native Redux计数器示例:解释有关reducer的信息

时间:2017-01-17 08:55:34

标签: javascript react-native redux

我正在学习本文的react-native和redux, https://github.com/alinz/example-react-native-redux/tree/master/Counter,我想理解为什么在文件夹reducers内,有index.js内容如下:

import counter from './counter';
export {
   counter
};

我不明白为什么我们需要这个,因为在同一个文件夹reducers中,counter.js的内容如下

export default function counter(state = initialState, action = {}) {
   ...
}

它已导出默认counter,为什么index.js再次执行

1 个答案:

答案 0 :(得分:1)

如果您的应用程序增加了大量的reducer,您可以从reducers'中导入nameHere。 (这只是一个方便)。此外,您的代码更容易重构'通常,因为您不需要更改实际导入,但您可以从同一个文件中导入多个。

// this is preferred
import { ScalesReducer, BoxReducer } from './reducers';

// does the same, takes more space (more distraction in your code)
import ScalesReducer from './reducers/ScalesReducer';
import BoxReducer from './reducers/BoxReducer';