Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
4.6k views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...