Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.5k views
in Technique[技术] by (71.8m points)

reactjs - How to catch react errors like use className instead of class or key missing for a loop while linting without ejecting cra

How to catch react errors like use className instead of class or key missing for a loop while linting without ejecting cra.

It's better to catch these errors in the lint itself as you usually don't see them unless the component itself is loaded and control these checking via pre-commit hooks like husky.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Package eslint-plugin-react-hooks is usefull to trap such error / warning.

yarn add eslint-plugin-react -D

Edit your package.json to enable the plugin and you can turn off, error, warn the rules which you prefer.

"eslintConfig": {
    "plugins": [
      "react"
    ],
    "extends": [
      "react-app",
      "react-app/jest",
      "plugin:react/recommended"
    ],
    "rules": {
      "eqeqeq": "off",
      "no-useless-escape": "off",
      "jsx-a11y/alt-text": "off",
      "react/prop-types": "off",
      "react/display-name": "off",
      "react-hooks/exhaustive-deps": "off",
      "react/no-unknown-property": "warn",
      "react/jsx-key": "warn"
    }
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...