簡體   English   中英

未找到規則“re​​act-hooks/exhaustive-deps”的定義

[英]Definition for rule 'react-hooks/exhaustive-deps' was not found

在我的代碼中添加// eslint-disable-next-line react-hooks/exhaustive-deps ,我收到以下 eslint 錯誤。

8:14 錯誤定義“react-hooks/exhaustive-deps”規則未找到

我參考了這篇文章來解決這個問題,但提到的解決方案在我的情況下不起作用。 任何線索如何抑制這個eslint錯誤?

PS我結合使用standardjs

這通常是因為.eslintrc插件配置中缺少react-hooks插件。 確保您已添加react-hooks ,如下例所示:

"plugins": ["react", "react-hooks",],

確保像這樣在 extends 和 plugins 數組中定義你的 react-hooks

"extends": [
    "react-hooks",
  ],
  "plugins": [
    "react-hooks"
  ],

確保您已將規則放在.eslintrc中的rules對象中。 僅安裝插件不足以讓規則開始工作

"react-hooks/exhaustive-deps": "warn",

我假設您已經將react-hooks插件添加到.eslintrcplugins數組中

不是一個完美的解決方案,而是改變:

// eslint-disable-next-line react-hooks/exhaustive-deps

到:

// eslint-disable-next-line

抑制了那個錯誤。

假設您正在使用vscode並且您的 package.json 中有必要的包,例如

"eslint-plugin-react-hooks": "^4.3.0",

並在你的eslintrc.js

其他答案的建議是什么,那么您可能只需要重新啟動

ESLint: Restart ESLint Server

cmd/ctrl + shift + P

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM