.eslintrc.js for React 17 and JSX without import 'react'

天涯浪子 提交于 2021-01-24 09:32:05

问题


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

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"
    }
  }
}

for react 17?

Thank's a lot


回答1:


You can read about it in React docs.

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"
  }
}
  • react-in-jsx-scope on github.


来源:https://stackoverflow.com/questions/64646248/eslintrc-js-for-react-17-and-jsx-without-import-react

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!