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

Utk*_*pta 28 javascript reactjs eslint standardjs react-hooks

添加// eslint-disable-next-line react-hooks/exhaustive-deps我的代码后,我收到以下 eslint 错误。

8:14 未找到规则“re​​act-hooks/exhaustive-deps”的错误定义

我参考了这篇文章来解决这个问题,但提到的解决方案在我的情况下不起作用。任何线索如何抑制这个eslint错误?

PS我结合使用standardjs

Eri*_*ärd 54

这通常是因为插件配置中react-hooks缺少.eslintrc插件。确保您已react-hooks按以下示例添加:

"plugins": ["react", "react-hooks",],
Run Code Online (Sandbox Code Playgroud)

  • 这确实应该被视为已接受的答案。 (6认同)

小智 6

确保像这样在 extends 和 plugins 数组中定义你的 react-hooks

"extends": [
    "react-hooks",
  ],
  "plugins": [
    "react-hooks"
  ],
Run Code Online (Sandbox Code Playgroud)

  • 这是不正确的。不要延长。遵循官方指南:https://reactjs.org/docs/hooks-rules.html (6认同)

小智 5

确保您已将规则rules放入.eslintrc. 仅安装插件不足以让规则开始工作

"react-hooks/exhaustive-deps": "warn",
Run Code Online (Sandbox Code Playgroud)

我假设您已经将react-hooks插件添加到了plugins数组中.eslintrc


Utk*_*pta 1

不是一个完美的解决方案,但正在改变:

// eslint-disable-next-line react-hooks/exhaustive-deps
Run Code Online (Sandbox Code Playgroud)

到:

// eslint-disable-next-line
Run Code Online (Sandbox Code Playgroud)

抑制了该错误。

  • 我建议不要使用 `// eslint-disable-next-line` 因为这将完全禁用下一行的所有 ESLint 规则。 (17认同)