vercel / swr-site

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

Feedback for “Arguments – SWR” #286

Open so2liu opened 2 years ago

so2liu commented 2 years ago

https://swr.vercel.app/docs/arguments#passing-objects

I am not sure about the two examples. Are they equal?

const { data: user } = useSWR(['/api/user', token], fetchWithToken)
const { data: orders } = useSWR(user ? ['/api/orders', user] : null, fetchWithUser)

First example has the logic to decide if the request /api/orders is to send by check user and set key to null.

How the second example does the same thing? By checking each value of the key object ({url: '...', args: user}) is undefined?

shuding commented 2 years ago

Great feedback! These two examples are not equivalent at all. We should update this to be more clear indeed.