Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Update SWR example to include fetcher function. (vercel#26520)
Browse files Browse the repository at this point in the history
* Previous example doesn't work

* Apply suggestions from code review

* Update docs/basic-features/data-fetching.md

* lint-fix

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
3 people committed Jun 24, 2021
1 parent 2017f2d commit 4c404a5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/basic-features/data-fetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,10 @@ The team behind Next.js has created a React hook for data fetching called [**SWR
```jsx
import useSWR from 'swr'

const fetcher = (url) => fetch(url).then((res) => res.json())

function Profile() {
const { data, error } = useSWR('/api/user', fetch)
const { data, error } = useSWR('/api/user', fetcher)

if (error) return <div>failed to load</div>
if (!data) return <div>loading...</div>
Expand Down

0 comments on commit 4c404a5

Please sign in to comment.