在 react 17 中不一定使用
import React from 'react';
但是如果我没有它,那么 eslint 给了我错误'React' must be in scope when using JSX react/react-in-jsx-scope
知道如何修改 .eslintrc.jsmodule.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"
}
}
}
react 17?非常感谢
最佳答案
您可以在 React docs 中阅读有关它的信息.
If you are using
eslint-plugin-react
, thereact/jsx-uses-react
andreact/react-in-jsx-scope
rules are no longer necessary and can be turned off or removed.
{
// ...
"rules": {
// ...
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off"
}
}
react-in-jsx-scope
on github . 要使其工作,您应该将这些规则添加到您的
eslint
中。配置,见 Extending or replacing the default ESLint config对于 Create-React-App 细节,每个框架都应该在他们的文档中有相关部分。
关于reactjs - .eslintrc.js 用于 React 17 和 JSX,无需导入 'react',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64646248/