Question presented to candidate: "What is Suspense, what actually triggers it, and what do you use it for today?"
What a strong answer should cover:
<Suspense fallback={...}>is a boundary: if any component below it suspends, React shows the fallback until it is ready.- It moves loading states from inside each component to a boundary above them, so a component never needs its own
isLoading. - What triggers it:
React.lazy,use()on an unresolved promise, and framework data loaders. Not arbitrary promises, and not a plainuseEffectfetch. - Behaviour is like an Error Boundary: React walks up to the nearest boundary.
- Placement is a design decision — it decides the granularity of your loading UI.
- Streaming SSR: the server sends the shell immediately and streams each boundary as it resolves, and boundaries hydrate independently.
useTransitionto avoid a fallback flash when updating already-visible content.- The main constraint: it does not manage or cache the promise — creating one during render restarts the request every render.
Clarifying questions expected:
- "Is the data coming from a framework loader or a Server Component, or being fetched client-side?" — that decides whether Suspense is even usable.
Code / implementation expected: Yes — a Suspense boundary around a lazy component and a use() read.