Last active
April 6, 2020 16:31
-
-
Save icyJoseph/7762a3e1415eeeee26df076e5dd5b68d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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