Used to render promise values with automatic error handling.
import { Await, useLoaderData } from "react-router";export 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() { const { book, reviews } = useLoaderData(); return ( <div> <h1>{book.title}</h1> <p>{book.description}</p> <React.Suspense fallback={<ReviewsSkeleton />}> <Await resolve={reviews} errorElement={ <div>Could not load reviews 😬</div> } children={(resolvedReviews) => ( <Reviews items={resolvedReviews} /> )} /> </React.Suspense> </div> );} Copy
import { Await, useLoaderData } from "react-router";export 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() { const { book, reviews } = useLoaderData(); return ( <div> <h1>{book.title}</h1> <p>{book.description}</p> <React.Suspense fallback={<ReviewsSkeleton />}> <Await resolve={reviews} errorElement={ <div>Could not load reviews 😬</div> } children={(resolvedReviews) => ( <Reviews items={resolvedReviews} /> )} /> </React.Suspense> </div> );}
Note: <Await> expects to be rendered inside of a <React.Suspense>
<Await>
<React.Suspense>
Used to render promise values with automatic error handling.
Note:
<Await>
expects to be rendered inside of a<React.Suspense>