Created
October 26, 2025 15:21
-
-
Save sriram-palanisamy-hat/96b610c6baa65bf4a06ad58187b5a7e2 to your computer and use it in GitHub Desktop.
What's a suspense boundary and what it does when throws a promise?
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 } from 'react'; | |
| import Albums from './Albums.js'; | |
| export default function ArtistPage({ artist }) { | |
| return ( | |
| <> | |
| <h1>{artist.name}</h1> | |
| <Suspense fallback={<Loading />}> | |
| <Albums artistId={artist.id} /> | |
| </Suspense> | |
| </> | |
| ); | |
| } | |
| function Loading() { | |
| return <h2> Loading...</h2>; | |
| } | |
| import { use } from "react"; | |
| import { fetchData } from "./data.js"; | |
| export default function Albums({ artistId }) { | |
| const albums = use(fetchData(`/${artistId}/albums`)); | |
| return ( | |
| <ul> | |
| {albums.map((album) => ( | |
| <li key={album.id}> | |
| {album.title} ({album.year}) | |
| </li> | |
| ))} | |
| </ul> | |
| ); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment