React-hooks/exhaustive-deps 未显示在 VS 代码中

Red*_*ron 6 reactjs eslint react-hooks

我有一个.eslintrc包含以下规则的文件:

"rules": {
    "prettier/prettier": "error",
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "error",
    "no-console": "warn"
},
Run Code Online (Sandbox Code Playgroud)

我已经安装了:eslint-plugin-prettiereslint-config-prettiereslint-plugin-react-hooks

"eslint.validate": [ "javascript", "javascriptreact", "html", "typescriptreact" ],我已经在 vscode 的 settings.json 中启用

但是当我删除 a 中所需的依赖项时useEffect,它没有显示我希望的错误

我还需要做什么?

小智 6

我使用react 18.2.0,react-scripts 5.0.1和react-app-rewired 2.2.1。您必须在.eslintrc.

{
  "plugins": [
    // ...
    "react-hooks" // for activate eslint checking react hooks
  ],
  "rules": {
    // ...
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "error"
  }
}
Run Code Online (Sandbox Code Playgroud)


hgb*_*123 2

在 中.eslintrc,除了添加之外,您还必须在列表中rules添加react-hooksplugins

{
  "plugins": [
    // ...
    "react-hooks"
  ],
  "rules": {
    // ...
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "error"
  }
}

Run Code Online (Sandbox Code Playgroud)