Quick Summary
useEffect synchronizes a component with something outside React: a subscription, the DOM, a network request, a timer. It is not a lifecycle hook and it is not the place for derived state. The effect function runs after the browser paints, and the optional cleanup runs before the next execution of the same effect and once on unmount.
The dependency array is compared item by item with Object.is . [] means "never re-run", [a, b] means "re-run when either changes", and omitting the array means "run after every render". Every reactive value used inside the effect belongs in the array β that is what the react-hooks/exhaustive-deps lint enforces, and disabling it is how stale closures become production bugs.
Race conditions are the second half of the story. A fetch started on one render can resolve after a newer fetch has already come back, overwriting fresh data with stale data.β¦