ConsoleTVs / sswr

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

Support synchronous `fetcher` function #25

Closed rauchg closed 2 years ago

rauchg commented 2 years ago

For local storage cases like localStorage, I ran into an obscure error where it was complaining that the return value didn't have .catch. I fixed by turning my sync fetcher into an async function.

Furthermore, it might be worth considering accepting the fetcher as the second param, since that's how SWR also works.

rauchg commented 2 years ago

(Great work on sswr btw! Enjoying it 🤗 )

ConsoleTVs commented 2 years ago

@rauchg I quickly checked the types for the fetcher function:

type SWRFetcher<D = any> = (...props: any[]) => Promise<D>;

I'm curious how it allowed you to use a fetcher function that didn't return a Promise. I will cover this use case, but may I know if you were using Typescript and/or vscode?

ConsoleTVs commented 2 years ago

Fixed here: https://github.com/ConsoleTVs/swrev/commit/815d5ee5a94ce2cee2d0a13a5de61caf96eea22c