相关疑难解决方法(0)

.eslintrc.js 用于 React 17 和 JSX,无需导入“react”

在反应 17 中不一定使用

import React from 'react';
Run Code Online (Sandbox Code Playgroud)

但是如果我没有它,那么 eslint 给了我错误

'React' must be in scope when using JSX react/react-in-jsx-scope
Run Code Online (Sandbox Code Playgroud)

知道如何修改 .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"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

反应 17?

非常感谢

reactjs eslint

15
推荐指数
2
解决办法
7533
查看次数

标签 统计

eslint ×1

reactjs ×1