React Hook useEffect has a missing dependency HELP

Hello, I’m making a meme generator (FCC Challenge) and I managed to easily create the App, but React is giving me this warning: ‘React Hook useEffect has a missing dependency’.
The quick solution according to React is to include values in the array ([values]), but if I do this, the App goes “crazy”. It bugs.
Code:
codigoo

Any solution?

Hello @maureSs.

React is complaining because it expects you to pass values as dependency since it is declared within the body of the component and being used inside useEffect. And doing so will trigger an infinite loop I believe because you are passing it as a dependency and setting its value within useEffect. I don’t think you are even using setValues correctly.

If you want to use the current value of state for setting state, you can use the callback method instead:

setValues(currentValues => ({...currentValues, allMemeImgs: memes}));

I hope that helps.

useEffect runs everytime your dependency changes.

If you pass values as dependency, but change values in this useEffect, then you changed the dependency (values), so it runs again.

So this is a infinite loop.