.eslintrc.js用于React 17和JSX而不导入'react'

问题描述

在反应17中不一定使用

import React from 'react';

但是如果我没有它,那么埃斯林特给了我错误

'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-reactreact/react-in-jsx-scope规则,可以将其关闭或删除。

{
  // ...
  "rules": {
    // ...
    "react/jsx-uses-react": "off","react/react-in-jsx-scope": "off"
  }
}