How do hooks map to the old class lifecycle methods?
Quick answer
componentDidMount → useEffect(fn, []); componentDidUpdate → useEffect(fn, [deps]); componentWillUnmount → the cleanup returned from useEffect.
In detail
There are no named lifecycle methods in function components — useEffect expresses them all. An effect with [] runs on mount; with deps it runs on relevant updates; its returned cleanup runs on unmount (and before re-runs). One effect with setup + cleanup replaces the split between componentDidMount and componentWillUnmount, keeping related logic together.
useEffect(() => {
const sub = subscribe(); // didMount
return () => sub.unsubscribe(); // willUnmount
}, []);Why interviewers ask this: Common when interviewers bridge from class to hooks knowledge.
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