ESLint exhaustive deps rule for useEffect causes infinite loop

Viewed 30

I've been using React for three weeks I guess, so bear with my lack of react knowledge.

I want to use useEffect whenever a certain state changes. But eslint exhaustive deps states that I should include more dependencies, which in turn triggers useEffect even though I don't want to

this works fine:

useEffect(() => {
     //do something
},[stateOne])

this causes an infinite loop:

useEffect(() => {
     //do something
},[stateOne, stateTwo])

While it may sound vague, the idea is that is it not ideal to just put a certain useEffect dependency so that it triggers only when that dependency changes? I thought the purpose of useEffect is that you have the option to trigger something depending on a certain dependency only.

0 Answers
Related