reactjs - ESLint 首选默认导出导入/prefer-default-export

标签 reactjs eslintrc

您好,我正在努力理解/让这个 eslint 错误在我的 React 项目中消失。

首选默认导出导入/prefer-default-export

Helpers.js 错误指向:

export function getItems() {
  fetch('./data/data_arr.js')
  .then(results => results.json())
  .then(results => this.setState({ items: results }));
}

导入函数:

从 '../helpers/helpers' 导入 { getItems };

componentDidMount() {
    getItems.call(this);
}

我已经尝试过,但没有成功:

"rules": {
     "import/prefer-default-export": off,
     ...
}

我需要在函数中添加“默认”吗? 导出默认函数 getItems() {...}

谢谢

最佳答案

"rules": {
     "import/prefer-default-export": "off",
     ...
}

单词off必须被引用。

关于reactjs - ESLint 首选默认导出导入/prefer-default-export,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52627477/

相关文章:

javascript - 什么是 ESLint 规则来防止在对象 prop 冒号后换行

javascript - 加载状态永远不会变为真??(React - Redux)

javascript - Webpack 未加载的静态图像

javascript - Unlayer EmailEditor 导入 React 会破坏应用程序

validation - 使用 React 和 Material-ui 进行表单验证

reactjs - 无法加载在 '@typescript-eslint' : Class extends value undefined is not a constructor or null 中声明的插件 '.eslintrc'

eslint-plugin-testing-library 没有捕获 lint 错误

javascript - 记住用户投票的 CSS 样式(赞成票和反对票)

javascript - 如何修复此 eslint 路径 Unresolved 错误?没有 Unresolved

import - 如何在 Svelte 中使用 Vite 和 ESlint 解析绝对路径?