From 13d1dd376314ba4e57849cc7ca18a23c1217327e Mon Sep 17 00:00:00 2001 From: Joshua Byrd Date: Wed, 23 Jun 2021 21:04:04 +1000 Subject: [PATCH 1/4] Previous example doesn't work --- docs/basic-features/data-fetching.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/basic-features/data-fetching.md b/docs/basic-features/data-fetching.md index 937181cbedbcf..a6d9398088ecf 100644 --- a/docs/basic-features/data-fetching.md +++ b/docs/basic-features/data-fetching.md @@ -826,7 +826,8 @@ The team behind Next.js has created a React hook for data fetching called [**SWR import useSWR from 'swr' function Profile() { - const { data, error } = useSWR('/api/user', fetch) + const fetcher = url => fetch(url).then(r => r.json()) + const { data, error } = useSWR('/api/user', fetcher) if (error) return
failed to load
if (!data) return
loading...
From a6bb88523bde21ef6b06d59684f125bace98de67 Mon Sep 17 00:00:00 2001 From: Lee Robinson Date: Wed, 23 Jun 2021 11:02:38 -0500 Subject: [PATCH 2/4] Apply suggestions from code review --- docs/basic-features/data-fetching.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/basic-features/data-fetching.md b/docs/basic-features/data-fetching.md index a6d9398088ecf..f41a6296bb03f 100644 --- a/docs/basic-features/data-fetching.md +++ b/docs/basic-features/data-fetching.md @@ -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 fetcher = url => fetch(url).then(r => r.json()) const { data, error } = useSWR('/api/user', fetcher) if (error) return
failed to load
From 1128333a9b962834bc9bc7025611befde0ecd86e Mon Sep 17 00:00:00 2001 From: Lee Robinson Date: Wed, 23 Jun 2021 11:02:59 -0500 Subject: [PATCH 3/4] Update docs/basic-features/data-fetching.md --- docs/basic-features/data-fetching.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/basic-features/data-fetching.md b/docs/basic-features/data-fetching.md index f41a6296bb03f..68a6796fae828 100644 --- a/docs/basic-features/data-fetching.md +++ b/docs/basic-features/data-fetching.md @@ -827,7 +827,6 @@ import useSWR from 'swr' const fetcher = url => fetch(url).then(res => res.json()); - function Profile() { const { data, error } = useSWR('/api/user', fetcher) From 1b96f9074998270a597ba5690b895432c4223aab Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 23 Jun 2021 23:35:35 -0500 Subject: [PATCH 4/4] lint-fix --- docs/basic-features/data-fetching.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/basic-features/data-fetching.md b/docs/basic-features/data-fetching.md index 68a6796fae828..436ee3fbe54fb 100644 --- a/docs/basic-features/data-fetching.md +++ b/docs/basic-features/data-fetching.md @@ -825,7 +825,7 @@ 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()); +const fetcher = (url) => fetch(url).then((res) => res.json()) function Profile() { const { data, error } = useSWR('/api/user', fetcher)