From 2c3624269ad8b9d53935603c65a7df7d21c9d1ea Mon Sep 17 00:00:00 2001 From: Joshua Byrd Date: Thu, 24 Jun 2021 14:41:15 +1000 Subject: [PATCH] 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: Lee Robinson Co-authored-by: JJ Kasper --- 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 937181cbedbcf..436ee3fbe54fb 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 { data, error } = useSWR('/api/user', fetch) + const { data, error } = useSWR('/api/user', fetcher) if (error) return
failed to load
if (!data) return
loading...