Open petrussola opened 3 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
https://swr.vercel.app/getting-started#example Language: en-US
The useUser exampled built in line 58 of
getting-started.en-US.mdx
file takesid
as param. However, the examples from line 84 do not pass it. Shouldn't the examples in lines 195 and 201 of beuseUser(id)
instead ofuseUser()
?