DEV Community

Discussion on: You don't know useEffect

Collapse
 
srikanth597 profile image
srikanth597

It's been sometime I used react,
If my memory is correct, ur useRef variable isMounted should also be automatically part of dependencies array doesn't it?
If u don't add it, IDE doesn't complain?

Maybe someone could u get this to my head.

Collapse
 
haosik profile image
Nikolay Mochanov

If I understood your question right - no, ref (isMounted in this case) should not be a part of dependencies because it is something different (from the 'state' for example) by nature. That said, changing useRef.current value does not cause the re-render, so it's just being changed 'silently' and only help the useEffects to fire when they really should.