gpt4 book ai didi

javascript - React-native Redux 计数器示例 : explain about reducer

转载 作者:行者123 更新时间:2023-12-03 05:13:48 24 4
gpt4 key购买 nike

我正在从这篇文章中学习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 = {}) {
...
}

它已经导出了默认的计数器,为什么index.js又这样做了

最佳答案

如果您的应用程序随着大量 reducer 而增长,您可以“从 reducer 导入 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';

关于javascript - React-native Redux 计数器示例 : explain about reducer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41692755/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com