Skip to content

Instantly share code, notes, and snippets.

@pkellner
Created January 7, 2022 17:01
Show Gist options
  • Save pkellner/28fdf658fefc9889bb3dcb7d82230592 to your computer and use it in GitHub Desktop.
Save pkellner/28fdf658fefc9889bb3dcb7d82230592 to your computer and use it in GitHub Desktop.
function Demo() {
function ProcessAndRender() {
const fetcher = (url) => fetch(url).then((r) => r.json());
const { data } = useSwr(
`https://jsonplaceholder.typicode.com/todos`,
fetcher,
{ suspense: true }
);
return (
<div className="container grid">
{data.map((rec) => {
return (
<div className="row" key={rec.id}>
<div className="col-2">{rec.userId}</div>
<div className="col-8">{rec.title}</div>
<div className="col-2">
{rec.completed === true ? "yes" : "no"}
</div>
</div>
);
})}
</div>
)
}
return (
<Suspense fallback={<div>fallback URL loading</div>}>
<ProcessAndRender />
</Suspense>
);
}
export default Demo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment