Skip to content

Instantly share code, notes, and snippets.

@raflyfahrezi
Created May 25, 2021 23:12
Show Gist options
  • Save raflyfahrezi/5e249784fff776c6a39237ba1c90f622 to your computer and use it in GitHub Desktop.
Save raflyfahrezi/5e249784fff776c6a39237ba1c90f622 to your computer and use it in GitHub Desktop.
fetcing data using swr
import React from 'react'
import useSWR from 'swr'
import { fetcher } from '../utils'
const index = () => {
const { data } = useSWR('... some API Fetch ...', fetcher)
return (
<div>
{data ? (
<div>
{data.map((item, index) => {
return (
<div>...</div>
)
})}
</div>
) : (
<div>
<p>Loading</p>
</div>
)}
</div>
)
}
export default index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment