.eslintrc.js用于React 17和JSX而不导入'react' [英] .eslintrc.js for React 17 and JSX without import 'react'

查看:152
本文介绍了.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?

非常感谢

推荐答案

您可以在

如果您使用的是 eslint-plugin-react ,则 react/jsx-uses-react react/react-in-jsx-scope 规则不再需要,可以将其关闭或删除.

If you are using eslint-plugin-react, the react/jsx-uses-react and react/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"
  }
}

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆