Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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.

like image 775
UtkarshPramodGupta Avatar asked Jan 06 '20 12:01

UtkarshPramodGupta


People also ask

How do you fix React Hooks exhaustive DEPS?

The "react-hooks/exhaustive-deps" rule warns us when we have a missing dependency in an effect hook. To get rid of the warning, move the function or variable declaration inside of the useEffect hook, memoize arrays and objects that change on every render or disable the rule.

How do you use Hooks in React?

Instead, always use Hooks at the top level of your React function, before any early returns. By following this rule, you ensure that Hooks are called in the same order each time a component renders. That's what allows React to correctly preserve the state of Hooks between multiple useState and useEffect calls.

How do you call a conditional hook?

React Hook "useClickAway" is called conditionally. React Hooks must be called in the exact same order in every component render. Did you accidentally call a React Hook after an early return?

What are the Hooks in React JS?

Hooks are functions that let you “hook into” React state and lifecycle features from function components. Hooks don't work inside classes — they let you use React without classes. (We don't recommend rewriting your existing components overnight but you can start using Hooks in the new ones if you'd like.)


1 Answers

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",], 
like image 73
Erik Töyrä Silfverswärd Avatar answered Sep 20 '22 07:09

Erik Töyrä Silfverswärd