Passing an array as dependency for useEffect in React

So… I need my effect to hit everytime an array im passing as dependency gets altered.
I quickly realized it causes an infinite loop.
I searched and searched and the one person on suggested passing [array.lenght] as the dependency and it ACTUALLY worked… but… its glitchy… looks VERY glitchy on the user interface…
Anyone here with a better idea?
Thanks in advance

You can pass JSON.stringify(outcomes) as the dependency list:

1 Like

You’re a damn genius, buddy… bless your heart!!!

By the way, I googled “useeffect array dependency” and that was the first hit. You gotta work on your google-fu!

Most definitely!!! Will work on that =)

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.