ConsoleTVs / sswr

🔥 Svelte stale while revalidate (SWR) data fetching strategy
MIT License
234 stars 11 forks source link

`fetcher` is sometimes ignored and it uses the default `fetch` #26

Closed rauchg closed 2 years ago

rauchg commented 2 years ago

I ran into a scenario where passing a custom fetcher to useSWR was still creating fetch calls.

I had to work around it as follows unfortunately:

  const swr = createSWR({ fetcher: readUser });
  const { data: user, revalidate } = swr.useSWR("usertest", {
    dedupingInterval: 0,
    revalidateOnFocus: false,
  });

I was noticing that if I passed fetcher to useSWR instead, I'd see XHR to /usertest even though my fetcher doesn't use XHR at all.

ConsoleTVs commented 2 years ago

That shall be fixed! The fetcher from the initial call will be respected if you revalidate or mutate from the given result func.

const { data: user, revalidate } = useSWR('...', { fetcher })

revalidate() // Should now respect fetcher.