swr icon indicating copy to clipboard operation
swr copied to clipboard

Make it possible to infer the fetcher's key

Open Yuddomack opened this issue 2 years ago • 4 comments

Hi!

I am using passing objects feature (https://swr.vercel.app/docs/arguments#passing-objects) like this.

image

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,

image

can be corrected correctly

image

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!

Yuddomack avatar Jul 10 '22 17:07 Yuddomack

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

codesandbox-ci[bot] avatar Jul 10 '22 17:07 codesandbox-ci[bot]

I think we might still need to keep this overload here for compatibility for now https://github.com/vercel/swr/pull/1640#issuecomment-974299780

promer94 avatar Jul 10 '22 17:07 promer94

Thanks for the quick feedback. I'll check it out!

Yuddomack avatar Jul 11 '22 01:07 Yuddomack

I understand the compatibility concerns but why can't it be changed in 2.0.0-beta already?

phaux avatar Aug 21 '22 18:08 phaux