如何配置Eslintrc并将React添加到ESLINT(使用Airbnb,Typescript)的情况下,而无需创建React App

发布于 2025-02-12 23:28:34 字数 615 浏览 0 评论 0原文

我的项目不使用Create-React-App。我正在上调我的eslint。如何对eslintrc.js文件正确添加反应?

目前,我在extend属性中都有这个:

extends: [
    'airbnb',
    'airbnb-typescript',
    'airbnb/hooks',
    // "plugin:@typescript-eslint/recommended",
    // "plugin:@typescript-eslint/recommended-requiring-type-checking",
    // "plugin:eslint-comments/recommended",
    'plugin:react/recommended',
    'plugin:jest/recommended',
    'plugin:prettier/recommended',
  ],

例如,现在Eslint抛出错误:

功能组件不是功能 声明linextreact/function-component-definition)

我如何只为我的react组件等使用箭头函数?

My project is not using create-react-app. I am upadting my Eslint. How do I add React properly to the eslintrc.js file?

Currently I have this in the extend property:

extends: [
    'airbnb',
    'airbnb-typescript',
    'airbnb/hooks',
    // "plugin:@typescript-eslint/recommended",
    // "plugin:@typescript-eslint/recommended-requiring-type-checking",
    // "plugin:eslint-comments/recommended",
    'plugin:react/recommended',
    'plugin:jest/recommended',
    'plugin:prettier/recommended',
  ],

For example now eslint throws error:

Function component is not a function
declarationeslintreact/function-component-definition)

How can I just use arrow functions for my React components etc?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没有你我更好 2025-02-19 23:28:34
"react/function-component-definition": [
  2,
  {
    namedComponents: "arrow-function",
    unnamedComponents: "arrow-function",
  },
],

“ react/function-component-definition”:[
2,,
{
名为COMPONENTS:“箭头函数”,
不愿透露姓名:“箭头功能”,
},,
],

只需在您的eslintrc.js文件中添加这些行。这仅允许您添加箭头功能。

"react/function-component-definition": [
  2,
  {
    namedComponents: "arrow-function",
    unnamedComponents: "arrow-function",
  },
],

"react/function-component-definition": [
2,
{
namedComponents: "arrow-function",
unnamedComponents: "arrow-function",
},
],

Just add these line in your eslintrc.js file. This only allow you to add arrow function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文