简体   繁体   English

未找到规则“re​​act-hooks/exhaustive-deps”的定义

[英]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插件添加到.eslintrcplugins数组中

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.

相关问题 React Hooks react-hooks/exhaustive-deps eslint 规则似乎过于敏感 - React Hooks react-hooks/exhaustive-deps eslint rule seems overly sensitive 如何在React中使用钩子实现componentDidMount以使其符合EsLint规则“ react-hooks / exhaustive-deps”:“ warn”? - How to implement componentDidMount with hooks in React to be in line with the EsLint rule “react-hooks/exhaustive-deps”: “warn”? 反应 useEffect 带有警告的钩子 react-hooks/exhaustive-deps - React useEffect hook with warning react-hooks/exhaustive-deps useEffect 和 'react-hooks/exhaustive-deps' linting - useEffect and 'react-hooks/exhaustive-deps' linting 带有自定义 IntersectionObserver 钩子的 react-hooks/exhaustive-deps 警告 - react-hooks/exhaustive-deps warning with custom IntersectionObserver hook React挂钩:如何使用react-hooks / exhaustive-deps规则在没有无限循环的情况下读取和更新挂钩中的状态 - React hooks: How to read & update state in hooks without infinite loops with react-hooks/exhaustive-deps rule 设计React Hooks可以防止React-Hooks / Exhaustive-deps警告 - Designing React Hooks prevent react-hooks/exhaustive-deps warning 我如何正确使用 useEffect 进行异步获取调用和反应? 反应钩子/详尽的deps - How do i properly use useEffect for a async fetch call with react? react-hooks/exhaustive-deps 如何解决`react-hooks/exhaustive-deps`的`React Hook useEffect缺少依赖`? - How to solve `React Hook useEffect has a missing dependency` of `react-hooks/exhaustive-deps`? ESLint 希望 setSate 作为 useEffect 的依赖,但这会导致无限循环(react-hooks/exhaustive-deps) - ESLint wants setSate as a dependency for useEffect but this causes an infinite loop (react-hooks/exhaustive-deps)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM