![](/img/trans.png)
[英]React Hooks react-hooks/exhaustive-deps eslint rule seems overly sensitive
[英]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
插件添加到.eslintrc
的plugins
數組中
不是一個完美的解決方案,而是改變:
// 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.