← Questions
React class components, lifecycle methods and hooks
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Snowflake's two coding screens round, last asked Jan 2026. It tests react, frontend and fundamentals.
A frontend fundamentals round: explain how React components handle state and side effects, first with class components and then with hooks, and reason through the bugs each style tends to produce. Expect to write or read short snippets while you answer.
Questions
- How does a class component work:
constructor,stateandsetState,render, and whythisbinding matters for handlers? - In what order do the lifecycle methods run on mount, on update and on unmount (
constructor,render,componentDidMount,shouldComponentUpdate,componentDidUpdate,componentWillUnmount)? What belongs in each? - How do you write the same behaviour with function components and hooks:
useState,useEffectwith its dependency array and cleanup function,useRef,useMemoanduseCallback? When does each run relative to rendering and to the browser paint? - How do class components and hooks reuse logic (higher-order components and render props versus custom hooks)?
- What are the rules of hooks, and why do they exist?
What a strong answer covers
- A correct mental model of render versus commit: rendering is pure, effects run after the commit, cleanup runs before the next effect and on unmount.
- Mapping each lifecycle method to its hook equivalent, and where the mapping is not exact (an effect with no dependency array runs after every render).
- Stale closures: an effect or callback that captures an old value of state or props, how it shows up (an interval that always logs the first value), and fixes such as functional
setState, correct dependencies or a ref. - Missing or extra dependencies, infinite effect loops caused by objects created during render, and when
useMemo/useCallbackactually help. - State updates being batched and asynchronous, so reading state right after
setStatereturns the old value.
Follow-ups
- Convert a given class component with a subscription in
componentDidMountand cleanup incomponentWillUnmountinto a function component. - Why does an effect run twice in development under Strict Mode, and what does that tell you about your effect?
- When would you choose
useLayoutEffectoveruseEffect?
Where it's asked
- Snowflake · Two coding screens · Last asked Jan 202660 min · Two back-to-back live coding rounds, often on the same day; some loops pair coding with system design · Varies: some screens forbid AI, some 2026 screens allow it. The scheduling email says.
What it tests
react · frontend · fundamentals
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
