vercel / swr-site

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

Documentation - getting started example - useUser missing param id? #106

Open petrussola opened 3 years ago

petrussola commented 3 years ago

https://swr.vercel.app/getting-started#example Language: en-US

The useUser exampled built in line 58 of getting-started.en-US.mdx file takes id as param. However, the examples from line 84 do not pass it. Shouldn't the examples in lines 195 and 201 of be useUser(id) instead of useUser()?

ivorivetta commented 2 years ago

Same feedback.

It's not like the swr hook knows which cache key to reference based on the name of the return variable, right? i.e.: const { user, isLoading } = useUser() does not magically link all the hooks outputting to user. I believe it's only the key in useSWR(key, fetcher) that performs this function and we need to pass id down to the hook to accomplish this.

If that logic tracks, we need to choose a pattern to pass data to child components. Not an expert, would drilling down through props be the simplest implementation to demonstrate?

Edit: I am slightly confused though, as it seems the final example on this page is to demonstrate this exact behavior of not having to drill down props