DEV Community

Discussion on: Need assistance with useEffect() dependencies

Collapse
 
jordyvandomselaar profile image
jordyvandomselaar • Edited

Hi @ptifur ,

Do you still need help with this? If so, would you mind creating a minimal reproducible example on something like CodeSandbox? That would make it easier for us to see what's going on :)

What I can say is that whenever you need to set state based on a previous value, like when you're flipping shouldStop, instead of doing setShouldStop(!shouldStop), try setShouldStop(prevShouldStop => !prevShouldStop). This ensures that you're always using the latest shouldStop to update it instead of accidentally using a previous value: reactjs.org/docs/hooks-reference.h...