Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.6k 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...