Close the earlier lessons and build this from the brief. The starter has the
pretend server, the cache, and an error boundary that takes a
fallback(error, reset) function and a resetKey prop.
The brief
- Load the topic list with
use(getTopicList()), and show a button for each topic. While the list loads, show Loading topics…. - Below the buttons, show the selected topic's title and summary with
use(getTopic(id)), starting with topic 1. - Switching topics is a transition: the old topic stays, faded, until the new one is ready.
- Hovering a button preloads its topic.
- Broken topic can't load. Show its error with a Try again button that removes it from the cache and resets the boundary. Choosing another topic also clears the error.
Acceptance checks:
- Clicking Transitions never shows Loading topic…; the old topic fades instead.
- Broken topic shows Topic 4 couldn't be loaded. and Try again sends a new request.
- After the error, clicking use shows that topic.
Runs with Vite on your computer: unzip, then
npm install and npm run dev. Hint 1: where the boundaries go
One <Suspense> around everything, for the list. Inside it, around the topic
details: the error boundary, then a second <Suspense>.
Hint 2: resetting without remounting
Give the error boundary resetKey={selectedId}, not key={selectedId}. A key
would make a new Suspense boundary on every switch, and the fallback would flash.
Show one solution
Runs with Vite on your computer: unzip, then
npm install and npm run dev. Check yourself
- What does
usedo with a promise that hasn't resolved yet? - Why must the promise passed to
usebe cached? - When does a transition not stop a Suspense fallback from showing?
Completion is saved in this browser only. It does not measure mastery.