Skip to content

Instantly share code, notes, and snippets.

@icyJoseph
Last active April 6, 2020 16:31
Show Gist options
  • Save icyJoseph/7762a3e1415eeeee26df076e5dd5b68d to your computer and use it in GitHub Desktop.
Save icyJoseph/7762a3e1415eeeee26df076e5dd5b68d to your computer and use it in GitHub Desktop.
import React from "react";
import useSWR from "swr";
import { GridSpinner } from "react-spinners-kit";
import { SlowSuspense } from "containers/SlowSuspense";
import { UserCard } from "components/UserCard";
const endpoint = "https://api.github.com";
const fetcher = key =>
fetch({ url: `${endpoint}/users/${key}` }).then(res => res.json());
const useGithubData = user => {
const { data } = useSWR(user, fetcher, {
suspense: true,
shouldRetryOnError: false,
revalidateOnFocus: false
});
return data;
};
const GithubData = ({ user }) => {
const data = useGithubData(user);
return <UserCard {...data} />
};
const Fallback = () => (
<div className="spinner-container">
<GridSpinner color="hotpink" />
</div>
);
export const App = () => (
<SlowSuspense fallback={<Fallback/>}>
<GithubData user="icyJoseph" />
</SlowSuspense>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment