vercel / swr-site

The official website for SWR.
https://swr.vercel.app
Apache License 2.0
481 stars 351 forks source link

Feedback for “Getting Started” #564

Open TeddyBo opened 7 months ago

TeddyBo commented 7 months ago

Hi!

"useUser" hook has "id" as an input argument

function useUser (id) {
  const { data, error, isLoading } = useSWR(`/api/user/${id}`, fetcher)

  return {
    user: data,
    isLoading,
    isError: error
  }
}

but components "Avatar" and "Content" call it without arguments.

function Content () {
  const { user, isLoading } = useUser()
  if (isLoading) return <Spinner />
  return <h1>Welcome back, {user.name}</h1>
}

How does it work?

koba04 commented 7 months ago

Thank you! This example should be useUser(id), I'll fix it.