安装并使用eslint-plugin-react-hooks

进入项目根目录

 

一、安装eslint-plugin-react-hooks:

cnpm i -D eslint-plugin-react-hooks

 

二、配置ESLint:

1.打开项目根目录的package.json

2.把

  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },

改为

  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ],
    "plugins": [
      "react-hooks"
    ],
    "rules": {
      "react-hooks/rules-of-hooks": "error"
    }
  },

3.重启项目

 

posted @ 2021-04-17 18:30  starlog  阅读(1949)  评论(0)    收藏  举报