Skip to content

Commit

Permalink
Update SWR example to include fetcher function. (#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 authored Jun 24, 2021
1 parent 94d7450 commit 2c36242
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 2c36242

Please sign in to comment.