[英]Definition for rule 'react-hooks/exhaustive-deps' was not found
I am getting the following eslint error after adding // eslint-disable-next-line react-hooks/exhaustive-deps
in my code.在我的代码中添加
// eslint-disable-next-line react-hooks/exhaustive-deps
,我收到以下 eslint 错误。
8:14 error Definition for rule 'react-hooks/exhaustive-deps' was not found
8:14 错误定义“react-hooks/exhaustive-deps”规则未找到
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?
任何线索如何抑制这个eslint错误?
PS I'm using standardjs in conjuction. PS我结合使用standardjs 。
This typically happens because the react-hooks
plugin is missing in the .eslintrc
plugin configuration.这通常是因为
.eslintrc
插件配置中缺少react-hooks
插件。 Ensure you have added react-hooks
as in the example below:确保您已添加
react-hooks
,如下例所示:
"plugins": ["react", "react-hooks",],
Make sure you define your react-hooks both in extends and plugins array like this确保像这样在 extends 和 plugins 数组中定义你的 react-hooks
"extends": [
"react-hooks",
],
"plugins": [
"react-hooks"
],
Make sure you have put the rule in the rules
object in your .eslintrc
.确保您已将规则放在
.eslintrc
中的rules
对象中。 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
我假设您已经将
react-hooks
插件添加到.eslintrc
的plugins
数组中
Not a perfect solution but changing:不是一个完美的解决方案,而是改变:
// eslint-disable-next-line react-hooks/exhaustive-deps
to:到:
// eslint-disable-next-line
suppressed that error.抑制了那个错误。
Assuming you are using vscode and you have in your package.json the necessary packages such as假设您正在使用vscode并且您的 package.json 中有必要的包,例如
"eslint-plugin-react-hooks": "^4.3.0",
and in your eslintrc.js
并在你的
eslintrc.js
what the other answers have suggested then you might have to just restart其他答案的建议是什么,那么您可能只需要重新启动
ESLint: Restart ESLint Server
from ESLint: Restart ESLint Server
从
cmd/ctrl + shift + P
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.