Skip to content

Instantly share code, notes, and snippets.

@brunosabot
Created January 29, 2022 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunosabot/6dd2b044779868123fdbdd7c8f6bfa94 to your computer and use it in GitHub Desktop.
Save brunosabot/6dd2b044779868123fdbdd7c8f6bfa94 to your computer and use it in GitHub Desktop.
import useSWR from "swr";
const fetcher = (...args) => fetch(...args).then((res) => res.json());
function MyRenderingComponent() {
const { data, error } = useSWR("https://brunosabot.dev/api/hello/", fetcher);
if (error) return <div>An error has occurred</div>;
if (!data) return <div>Loading...</div>;
return <div>{data.name}</div>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment