What is useEffect for and when does it run?
Quick answer
It synchronises a component with external systems (network, DOM, subscriptions, timers). Effects run after the render is committed to the screen.
In detail
useEffect handles side effects — anything outside React's render output. It runs after paint, so it never blocks rendering. The dependency array controls re-runs: omitted = every render, [] = once on mount, [a, b] = when a or b changes. The mental model is synchronisation, not lifecycle: keep something external in sync with your state.
useEffect(() => {
document.title = `Count: ${count}`;
}, [count]); // re-run only when count changesWhy interviewers ask this: Effects are the most misused hook — interviewers test it hard.
Common follow-up questions
- →What does an empty dependency array mean?
- →What runs on unmount?
This is 1 of 118+ questions in the React Interview Kit
Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.
⚡ Get the React Interview Kit → ₹399