← Questions

React class components, lifecycle methods and hooks

0
SnowflakeCodingLast asked Jan 2026

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

  1. How does a class component work: constructor, state and setState, render, and why this binding matters for handlers?
  2. 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?
  3. How do you write the same behaviour with function components and hooks: useState, useEffect with its dependency array and cleanup function, useRef, useMemo and useCallback? When does each run relative to rendering and to the browser paint?
  4. How do class components and hooks reuse logic (higher-order components and render props versus custom hooks)?
  5. 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/useCallback actually help.
  • State updates being batched and asynchronous, so reading state right after setState returns the old value.

Follow-ups

  • Convert a given class component with a subscription in componentDidMount and cleanup in componentWillUnmount into 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 useLayoutEffect over useEffect?

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

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