Module 6 of 7

React Suspense

Suspense lets a component wait for something (data, code, an image) while React shows a fallback, written as if the data were already there. The core is one line: const product = use(productPromise). If the promise is pending, React stops rendering that component and shows the nearest <Suspense fallback>. If it rejects, the nearest error boundary takes over. When it fulfills, React renders again and use returns the value.

The rest of this module is about doing that well:

The examples use the product store with a fake API whose requests log when they start and finish, so every timeline here (milliseconds since the click, rounded to 50) was recorded in Chrome (examples/product-store/src/lessons/suspense).

Suspense for data works with any promise, but in a real app the promises usually come from a framework or a data library (Next.js, React Router, TanStack Query, Relay) that handles caching and invalidation for you. This module shows what they do underneath.

Start with “Data Fetching with use”All notesInterview questions

The notes

Read them in order. Each one builds on the ones before it.

01Must know

Data Fetching with use

Promises, use(promise), Suspense and error boundaries, and what really happens when use “throws”.

Read
03Must know

Optimistic UI

useOptimistic shows a review before the server confirms it; useFormStatus shows the form is busy.

Read
04Good to know

Suspending on Images

Keep new details from appearing next to an old picture, and keep a broken picture from breaking the card.

Read
06Must know

Waterfalls and Caching

Requests that wait for each other, starting them together, and the HTTP cache that survives a reload.

Read