57

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.

UtkarshPramodGupta
  • 7,486
  • 7
  • 30
  • 54

6 Answers6

111

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",],
8

Make sure you define your react-hooks both in extends and plugins array like this

"extends": [
    "react-hooks",
  ],
  "plugins": [
    "react-hooks"
  ],
JupiterAmy
  • 374
  • 2
  • 11
5

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

Mark Shulhin
  • 119
  • 5
  • Will `"react-hooks/exhaustive-deps": "off"` or `"react-hooks/exhaustive-deps": 0` work to disable globally ? – Taylor Austin Sep 20 '20 at 01:35
  • Hey, Taylor, yes both "off" and 0 should work to disable the rule. It depends on what you refer to as "global" in this case. If the eslint config is in your application folder then it will turn it off for the application workspace, if it is a global config and used in many projects it will disable it globally – Mark Shulhin Oct 23 '20 at 13:35
2

Not a perfect solution but changing:

// eslint-disable-next-line react-hooks/exhaustive-deps

to:

// eslint-disable-next-line

suppressed that error.

UtkarshPramodGupta
  • 7,486
  • 7
  • 30
  • 54
2

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

Byron
  • 691
  • 9
  • 9
2

Put below code to package.json

"eslintConfig": {
  "extends": "react-app"
}
MickeyWoW
  • 41
  • 5
  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 04 '22 at 08:42
  • this worked for me create-react-app version 5.0.1 react 17 – Nigel Savage Oct 27 '22 at 14:50