[英].eslintrc.js for React 17 and JSX without import 'react'
在反應 17 中不一定使用
import React from 'react';
但是如果我沒有它,那么 eslint 給了我錯誤
'React' must be in scope when using JSX react/react-in-jsx-scope
知道如何修改 .eslintrc.js
module.exports = {
parser: "babel-eslint",
env: {
browser: true,
node: true,
es6: true,
jest: true,
},
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:jsx-a11y/recommended"
],
plugins: [
"react",
"react-hooks",
"jsx-a11y",
],
rules: {
strict: 0,
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
},
settings: {
react: {
version: "detect"
}
}
}
反應 17?
非常感謝
你可以在React docs 中閱讀它。
如果您使用
eslint-plugin-react
,則react/jsx-uses-react
和react/react-in-jsx-scope
規則不再需要,可以關閉或刪除。
{
// ...
"rules": {
// ...
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off"
}
}
為了使其工作,您應該將這些規則添加到您的eslint
配置中,請參閱擴展或替換Create-React-App 細節的默認 ESLint 配置,每個框架都應在其文檔中具有相關部分。
你需要在.eslintrc.js
文件中添加plugin:react/jsx-runtime
來extends
。
喜歡是:
module.exports = {
extends: [
'plugin:react/recommended',
'airbnb',
'plugin:react/jsx-runtime',
]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.