How Suspense Detects 'Not Ready'
You'll learn how React's Suspense component knows when a child isn't ready to render yet.
The Promise-Throwing Signal
Suspense works on a beautifully simple protocol: when a component isn't ready to render, it throws a Promise. Yes, literally throws it like an error! Suspense catches this thrown Promise, displays the fallback UI, and tracks the Promise. When the Promise resolves, React retries rendering the component.
Think of it like a restaurant kitchen: if a chef realizes they're missing an ingredient mid-preparation, they throw their order ticket back to the expeditor (Suspense), who tells the waiter to show a "preparing your meal" message to the customer. When the ingredient arrives (Promise resolves), the expeditor sends the ticket back to the chef to try again.
The Detection Mechanism
Here's what happens under the hood:
- Component begins rendering and realizes it needs data that isn't available yet
- Throws a Promise representing the loading state
- Suspense catches the thrown Promise (like a catch block catches errors)
- Suspense displays the fallback UI you specified
- React attaches a handler to the Promise's
.then() - When resolved, React triggers a re-render of the suspended subtree
- Component tries again — if ready, renders normally; if not, throws again
This isn't magic—it's JavaScript's error-throwing mechanism repurposed brilliantly. The key insight: components can communicate their "not ready" state by throwing something Suspense recognizes and tracks.
Key Takeaway: Suspense detects unready components by catching thrown Promises, which serve as signals that rendering should be paused until the Promise resolves.