简体   繁体   English

在 React Native 中导出默认 {}

[英]Export default {} in React Native

I'm new to react native and I am trying to understand the export function.我是本机反应的新手,我正在尝试了解导出功能。

I've seen codes in which the end of the code says export default {} .我见过代码末尾说export default {}的代码。 But what does this do?但这有什么作用呢? Export an object that's empty?导出一个空的对象?

For example, in this code, is this doing anything relevant?:例如,在这段代码中,这是否在做任何相关的事情?:

export const generateRGB = () => {
    const r = Math.floor(Math.random() * 255);
    const g = Math.floor(Math.random() * 255);
    const b = Math.floor(Math.random() * 255);
    return { r, g, b }
};

export const mutateRGB = ({ r, g, b }) => {
    const newR = r + Math.floor(Math.random() * 20) + 10;
    const newG = g + Math.floor(Math.random() * 20) + 10;
    const newB = b + Math.floor(Math.random() * 20) + 10;
    return { r: newR, g: newG, b: newB }
};
  
export default {};

There are linter rules that require a default export, even if there are named exports in the module.即使模块中有命名的导出,也有需要默认导出的 linter 规则。 This may attempt to satisfy that.这可能试图满足这一点。

Interestingly, general sentiment seems to be swinging AGAINST default exports, and I know I prefer not to use them.有趣的是,普遍情绪似乎正在反对默认出口,我知道我不想使用它们。 Blog post with more info on that (not mine): https://humanwhocodes.com/blog/2019/01/stop-using-default-exports-javascript-module/包含更多信息的博客文章(不是我的): https : //humanwhocodes.com/blog/2019/01/stop-using-default-exports-javascript-module/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM