Lesson 16 of 80
React.lazy splits your bundle so a component's code only loads when it's actually needed — Suspense is what shows a fallback while React waits for it.
13 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 2
A lazy component's dynamic import fails to load (e.g. a network error). Does the Suspense fallback stay showing forever?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
React.lazy(() => import("./Chart")) doesn't load Chart's code immediately — it returns a component that, the first time it's rendered, kicks off the dynamic import() and suspends until that code arrives. <Suspense fallback={...}> is the boundary that catches that suspension and shows something in the meantime.
const Chart = React.lazy(() => import("./Chart"));
function Dashboard() {
return (
<Suspense fallback={<Spinner />}>
<Chart data={data} />
</Suspense>
);
}
Before Chart's code finishes downloading, <Spinner /> shows. Once it arrives, React swaps in the real Chart — the user never sees a blank gap or a broken render, and Chart's ~50kb of code never had to be in the initial bundle at all.
<Suspense fallback={<Spinner />}> wraps a subtree that might not be ready yet.
React.lazy. It's a general mechanism for "pause rendering until this async thing resolves" — data-fetching libraries and React's own newer APIs (use()) can suspend too, not just code-split components.Suspense boundary can wrap multiple lazy components. If two siblings are both loading, one fallback covers both — you don't need (and usually don't want) a separate spinner for every single lazy piece."How would you reduce this app's initial bundle size?" is a very concrete performance question, and code-splitting heavy, rarely-used routes/components behind React.lazy + Suspense is usually the single highest-leverage answer.