Created
June 16, 2020 21:21
-
-
Save toruticas/b60107d3add0d9a170b4e2e608b14aca 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, { FC } from 'react' | |
import { SWRConfig } from 'swr' | |
import axios from 'axios' | |
import { ProfileContainer } from './ProfileContainer' | |
import './App.css' | |
const fetcher = (url: string) => | |
axios(url).then( | |
response => | |
new Promise(resolve => | |
setTimeout(() => { | |
resolve(response) | |
}, 1000), | |
), | |
) | |
const App: FC = () => ( | |
<SWRConfig | |
value={{ | |
fetcher, | |
suspense: true, | |
}} | |
> | |
<div className="App"> | |
<h1>Profile</h1> | |
<ProfileContainer /> | |
</div> | |
</SWRConfig> | |
) | |
export { App } |
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, { FC, Suspense } from 'react' | |
import { ProfileData } from './ProfileData' | |
const ProfileContainer: FC = () => ( | |
<Suspense fallback="loading..."> | |
<ProfileData /> | |
</Suspense> | |
) | |
export { ProfileContainer } |
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, { FC } from 'react' | |
import useSWR from 'swr' | |
import './ProfileData.css' | |
const ProfileData: FC = () => { | |
const { data } = useSWR('https://api.github.com/users/toruticas') | |
return ( | |
<div className="ProfileData"> | |
<img | |
alt={data?.data?.name} | |
src={data?.data?.avatar_url} | |
style={{ height: 260, width: 260 }} | |
/> | |
<h2> | |
{data?.data?.name} | |
<br /> | |
<small>{data?.data?.login}</small> | |
</h2> | |
<p>{data?.data?.bio}</p> | |
</div> | |
) | |
} | |
export { ProfileData } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment