swr
swr copied to clipboard
Make it possible to infer the fetcher's key
Hi!
I am using passing objects feature (https://swr.vercel.app/docs/arguments#passing-objects) like this.

Unfortunately, This obviously leads to incorrect execution. But you won't know until execute project.
because this fetcher infers the type as a bare fetcher
, it shows no error information.
but, enable key inference with this update,

can be corrected correctly

I looked at swr2 (also 1.3), If only a fetcher and a key exist, there is no need to infer that it is a bare fetcher
.
so I think it would be better to inform the user that this is an incorrect usage.
Please consider this change. thank you for read!
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Latest deployment of this branch, based on commit de625fd9a983b67081b2b47fac0cb2771c776294:
Sandbox | Source |
---|---|
SWR-Basic | Configuration |
SWR-States | Configuration |
SWR-Infinite | Configuration |
SWR-SSR | Configuration |
I think we might still need to keep this overload here for compatibility for now https://github.com/vercel/swr/pull/1640#issuecomment-974299780
Thanks for the quick feedback. I'll check it out!
I understand the compatibility concerns but why can't it be changed in 2.0.0-beta already?