Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript React native Redux计数器示例:解释有关reducer的信息_Javascript_React Native_Redux - Fatal编程技术网

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

Javascript React native Redux计数器示例:解释有关reducer的信息,javascript,react-native,redux,Javascript,React Native,Redux,我正在从这篇文章中学习react native和redux, ,我想了解为什么在文件夹缩减器中有一个index.js,其内容如下: import counter from './counter'; export { counter }; 我不明白为什么我们需要这个,因为在同一个文件夹reducer中,有counter.js,内容如下 export default function counter(state = initialState, action = {}) { ... }

我正在从这篇文章中学习react native和redux, ,我想了解为什么在文件夹缩减器中有一个index.js,其内容如下:

import counter from './counter';
export {
   counter
};
我不明白为什么我们需要这个,因为在同一个文件夹reducer中,有counter.js,内容如下

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

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

如果您的应用程序增长时使用了大量的减缩器,那么您可以“从减缩器中导入名称”。这只是一种方便。此外,您的代码更容易进行“重构”,因为您不需要更改实际的导入,但您可以从同一个文件导入多个

// 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';

谢谢,如果你不介意的话,我想再问一件关于进口的事。从“./app/reducers”导入reducer,但在文件夹app中,没有文件reducers.js,只有index.js和recipies.js。这是否意味着当它找不到reducers.js时,它会返回到index.jsHi-Thang,它确实会获取该文件夹的索引,这是可以配置的,但我假设您使用的是默认设置。在这里你会发现一个更实际的例子