Created
February 8, 2026 19:01
-
-
Save markmals/8900395de91a5e3b29b9d4326b0bf65b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Suspense, use } from "react"; | |
| import { ErrorBoundary } from "react-error-boundary"; | |
| export async function loader() { | |
| // not awaited | |
| const reviews = getReviews(); | |
| // awaited (blocks the transition) | |
| const book = await fetch("/api/book").then(res => res.json()); | |
| return { book, reviews }; | |
| } | |
| function Book({ loaderData }: Route.ComponentProps) { | |
| const { book, reviews } = loaderData; | |
| return ( | |
| <div> | |
| <h1>{book.title}</h1> | |
| <p>{book.description}</p> | |
| <Suspense fallback={<ReviewsSkeleton />}> | |
| <ErrorBoundary fallback={<div>Could not load reviews 😬</div>}> | |
| <Reviews items={reviews} /> | |
| </ErrorBoundary> | |
| </Suspense> | |
| </div> | |
| ); | |
| } | |
| function Reviews({ items }: { items: Promise<Review[]> }) { | |
| const resolvedReviews = use(items); | |
| return ( | |
| <ul> | |
| {resolvedReviews.map(review => ( | |
| <li>{review.text}</li> | |
| ))} | |
| </ul> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment