英文:
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。
英文:
I am getting the following eslint error after adding // eslint-disable-next-line react-hooks/exhaustive-deps
in my code.
> 8:14 error Definition for rule 'react-hooks/exhaustive-deps' was not found
I referred to this post to fix this but the solution mentioned doesn't work in my case. Any clue how to suppress this eslint error?
PS I'm using standardjs in conjuction.
答案1
得分: 111
这通常是因为.eslintrc
插件配置中缺少react-hooks
插件而发生的。请确保您已按下面的示例添加了react-hooks
:
"plugins": ["react", "react-hooks"]
英文:
This typically happens because the react-hooks
plugin is missing in the .eslintrc
plugin configuration. Ensure you have added react-hooks
as in the example below:
"plugins": ["react", "react-hooks",],
答案2
得分: 8
"extends": [
"react-hooks",
],
"plugins": [
"react-hooks"
]
英文:
Make sure you define your react-hooks both in extends and plugins array like this
"extends": [
"react-hooks",
],
"plugins": [
"react-hooks"
],
答案3
得分: 5
确保你已将规则放入你的.eslintrc
中的rules
对象中。仅安装插件是不足以使规则开始生效的。
"react-hooks/exhaustive-deps": "warn"
我假设你已经将react-hooks
插件添加到.eslintrc
中的plugins
数组中。
英文:
Make sure you have put the rule in the rules
object in your .eslintrc
. Installing the plugin alone is not enough for the rules to start working
"react-hooks/exhaustive-deps": "warn",
and I assume you have already added react-hooks
plugin into the plugins
array in the .eslintrc
答案4
得分: 2
不是一个完美的解决方案,但是将:
// eslint-disable-next-line react-hooks/exhaustive-deps
更改为:
// eslint-disable-next-line
可以抑制该错误。
英文:
Not a perfect solution but changing:
// eslint-disable-next-line react-hooks/exhaustive-deps
to:
// eslint-disable-next-line
suppressed that error.
答案5
得分: 2
假设您正在使用 vscode,并且在您的 package.json 中已经有了必要的包,例如
"eslint-plugin-react-hooks": "^4.3.0",
并且在您的 eslintrc.js
中按照其他答案建议的配置,那么您可能只需要从
cmd/ctrl + shift + P
重新启动 ESLint 服务器
ESLint: Restart ESLint Server
。
英文:
Assuming you are using vscode and you have in your package.json the necessary packages such as
"eslint-plugin-react-hooks": "^4.3.0",
and in your eslintrc.js
what the other answers have suggested then you might have to just restart
ESLint: Restart ESLint Server
from
cmd/ctrl + shift + P
答案6
得分: 2
"eslintConfig": {
"extends": "react-app"
}
英文:
Put below code to package.json
"eslintConfig": {
"extends": "react-app"
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论