本文介绍了.eslintrc.js用于React 17和JSX而不导入'react'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在反应17中不一定要使用

in react 17 is not necessarily use

import React from 'react';

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

but if i don't have it, so eslint gave me error

'React' must be in scope when using JSX react/react-in-jsx-scope

任何想法如何修改.eslintrc.js

any idea how modify .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?

非常感谢

推荐答案

您可以在反应文档.

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

  • github上的react-in-jsx-scope .
  • 这篇关于.eslintrc.js用于React 17和JSX而不导入'react'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 06:15