Data Fetching with use
Promises, use(promise), Suspense and error boundaries, and what really happens when use “throws”.
ReadModule 6 of 7
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:
useDeferredValue: keep a search box responsive.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.
Read them in order. Each one builds on the ones before it.
Promises, use(promise), Suspense and error boundaries, and what really happens when use “throws”.
ReadOne promise per id, and startTransition to keep the old page instead of a fallback, without a flickering spinner.
ReaduseOptimistic shows a review before the server confirms it; useFormStatus shows the form is busy.
ReadKeep new details from appearing next to an old picture, and keep a broken picture from breaking the card.
ReadA search box that stays responsive while results load; a transition around the input loses keystrokes (recorded).
ReadRequests that wait for each other, starting them together, and the HTTP cache that survives a reload.
Read