Skip to content

Instantly share code, notes, and snippets.

@toruticas
Created June 16, 2020 21:21
Show Gist options
  • Save toruticas/b60107d3add0d9a170b4e2e608b14aca to your computer and use it in GitHub Desktop.
Save toruticas/b60107d3add0d9a170b4e2e608b14aca to your computer and use it in GitHub Desktop.
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 }
import React, { FC, Suspense } from 'react'
import { ProfileData } from './ProfileData'
const ProfileContainer: FC = () => (
<Suspense fallback="loading...">
<ProfileData />
</Suspense>
)
export { ProfileContainer }
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