Skip to content

Instantly share code, notes, and snippets.

@pkellner
Created January 7, 2022 16:59
Show Gist options
  • Save pkellner/5d809ca32f6ea9990aed303d61866f2a to your computer and use it in GitHub Desktop.
Save pkellner/5d809ca32f6ea9990aed303d61866f2a to your computer and use it in GitHub Desktop.
function Demo() {
const fetcher = (url) => fetch(url).then((r) => r.json());
const { data } = useSwr(
`https://jsonplaceholder.typicode.com/todos`,
fetcher,
{ suspense: false }
);
if (!data) return <div>Loading... (pre-Suspense)</div>;
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>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment