Unverified Commit 2c362426 authored by Joshua Byrd's avatar Joshua Byrd Committed by GitHub

Update SWR example to include fetcher function. (#26520)

* Previous example doesn't work

* Apply suggestions from code review

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

* lint-fix
Co-authored-by: 's avatarLee Robinson <me@leerob.io>
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 94d7450a
...@@ -825,8 +825,10 @@ The team behind Next.js has created a React hook for data fetching called [**SWR ...@@ -825,8 +825,10 @@ The team behind Next.js has created a React hook for data fetching called [**SWR
```jsx ```jsx
import useSWR from 'swr' import useSWR from 'swr'
const fetcher = (url) => fetch(url).then((res) => res.json())
function Profile() { 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 (error) return <div>failed to load</div>
if (!data) return <div>loading...</div> if (!data) return <div>loading...</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment