useEffect runs side effects after React commits DOM updates and the browser paints. The dependency array controls when effects re-run, and the cleanup function handles teardown before the next invocation or unmount.
useEffect is a React hook for synchronizing a component with an external system. It accepts a setup function and an optional dependency array. React calls the setup function after the browser has painted the committed DOM changes, not during the render phase.
The dependency array tells React when to re-run the effect. An empty array means run once on mount. Omitting the array means run after every render. Listing specific values means re-run only when those values change, compared with Object.is.
The setup function can return a cleanup function. React calls cleanup before re-running the effect with new values and one final time when the component unmounts. Each cleanup closes over the values from the render that created it, not the current render.
Interview framing: define useEffect Lifecycle in one sentence, then explain one concrete runtime behavior and one common pitfall with a short code example.