Question presented to candidate: "We migrated to React 18 and turned on transitions. Now, occasionally, two parts of the same screen show different values for the same piece of global state. What is happening, and how do you fix it?"
What a strong answer should cover:
- Tearing: a single committed screen displaying two different values of the same source of truth.
- Why React 18 made it possible: concurrent rendering can interrupt and resume a render, so a mutable external value can change mid-render.
- Why React's own state is immune — it is snapshotted per render — while an external store read directly in render is not.
useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)as the official fix, and that it deliberately forces a synchronous, non-interruptible re-render.getSnapshotmust return a cached value; returning a fresh object each call is an infinite loop.getServerSnapshotexists for SSR, where there is no store to subscribe to.- That modern libraries (Redux, Zustand, Jotai) already call this internally — you rarely write it by hand.
Clarifying questions expected:
- "Is the state in a React store or an external one — a module variable, a Redux store, a browser API?"
- "Are we using transitions or Suspense anywhere near this subtree?"
Code / implementation expected: Yes — a useSyncExternalStore call with a correct, cached getSnapshot.