Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omitting fetcher function argument is ambiguous? #148

Open
tmladek opened this issue Mar 21, 2021 · 6 comments
Open

Omitting fetcher function argument is ambiguous? #148

tmladek opened this issue Mar 21, 2021 · 6 comments
Labels
help wanted Extra attention is needed

Comments

@tmladek
Copy link

tmladek commented Mar 21, 2021

The README states:

Note that fetcher can be any asynchronous function, so you can use your favorite data-fetching library to handle that part. If ommitted, swrv uses the Fetch api.

But later also:

To only retrieve a swrv cache response without revalidating, you can omit the fetcher function from the useSWRV call.

So, which one is it? :) Or am I misunderstanding what omitting means in the first case?

@darrenjennings
Copy link
Contributor

yes it is ambiguous, thanks for noting! We need to document and maybe add some tests so it's clear. It should be:

- To only retrieve a swrv cache response without revalidating, you can omit the fetcher function from the useSWRV call
+ To only retrieve a swrv cache response without revalidating, you can set the fetcher function to `null` from the useSWRV call 

If it is "omitted" (aka undefined) then the Fetch api will be used.

if (typeof fn === 'undefined') {

@darrenjennings
Copy link
Contributor

Relevant swr issue: vercel/swr#738

@tochoromero
Copy link
Contributor

This is great, but the typings for it do not allow null, it should be a quick fix to just add null to the type definition.

@darrenjennings darrenjennings added the help wanted Extra attention is needed label Feb 2, 2022
@LumaKernel
Copy link

My PR resolves typing problem.
#274

@LumaKernel
Copy link

Current doc is not ambiguous for me, function calls f(), f(undefined) and f(undefined, undefined) have the same arguments (geek note: except argument length). In JS, omitting argument always means supplying undefined.

Yeah, but I think it's good to clarify the doc.

@LumaKernel
Copy link

afaik, the null fetcher behaves like Promise.race([]) or () => new Promise<never>(() => {}) (meaning resolves after infinite minutes), but isVaildating value differs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants