在 React Native 中导出默认 {}

Export default {} in React Native

我是 React Native 的新手,正在尝试了解导出功能。

我见过代码末尾写着 export default {} 的代码。但这有什么作用呢?导出空对象?

例如,在这段代码中,这是在做任何相关的事情吗?:

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 {};

有些 linter 规则需要默认导出,即使模块中有命名导出也是如此。这可能会尝试满足这一点。

有趣的是,普遍情绪似乎在反对默认导出,我知道我不想使用它们。博客 post 提供更多相关信息(不是我的):https://humanwhocodes.com/blog/2019/01/stop-using-default-exports-javascript-module/