Replies: 1 comment 2 replies
-
The fetcher would still have to be an async function (eg returns a promise) but I think you'd still be able to just call the callback within the fetcher. Though at that point you may be ignoring the data that What's your current implementation look like? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The Question
I'm trying to use the SWR hook with a fetcher that's not a promise but rather accepts a callback as the last argument of the function. Is it possible to use
useSWR
(or maybe another hook) that would work with a callback fetcher?My Use Case
I'm using
firebase/firestore
to store the data and I've separated the business logic from the view and theservices/
are responsible for updating and getting the data from thefirestore
. Right now my services accept arguments like query parameters, ids, etc along with a callback function that would return the new data when a new data snapshot is available.I wanted to somehow wrap the
useSWR
hook or maybe use another hook to be able to get the data from the service with a callback but wasn't able to do so.Maybe someone has already figured it out and knows how to use
swr
with callback-based fetchers?Beta Was this translation helpful? Give feedback.
All reactions