Skip to content

Instantly share code, notes, and snippets.

@sriram-palanisamy-hat
Created October 26, 2025 15:21
Show Gist options
  • Select an option

  • Save sriram-palanisamy-hat/96b610c6baa65bf4a06ad58187b5a7e2 to your computer and use it in GitHub Desktop.

Select an option

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?
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