Open so2liu opened 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?
{url: '...', args: user}
Great feedback! These two examples are not equivalent at all. We should update this to be more clear indeed.
https://swr.vercel.app/docs/arguments#passing-objects
I am not sure about the two examples. Are they equal?
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?