“react-hooks/exhaustive-deps” 规则的定义未找到。

huangapple go评论85阅读模式
英文:

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"
}

huangapple
  • 本文由 发表于 2020年1月6日 20:06:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611822.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定