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

Support synchronous fetcher function #25

Closed
rauchg opened this issue Nov 21, 2021 · 3 comments
Closed

Support synchronous fetcher function #25

rauchg opened this issue Nov 21, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@rauchg
Copy link

rauchg commented Nov 21, 2021

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
Copy link
Author

rauchg commented Nov 21, 2021

(Great work on sswr btw! Enjoying it 🤗 )

@ConsoleTVs ConsoleTVs self-assigned this Nov 21, 2021
@ConsoleTVs ConsoleTVs added the bug Something isn't working label Nov 21, 2021
@ConsoleTVs
Copy link
Owner

ConsoleTVs commented Nov 21, 2021

@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
Copy link
Owner

Fixed here: ConsoleTVs/swrev@815d5ee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants