Data behaves weird if different fetcher is used for different API routes #1392
Unanswered
swarup4741
asked this question in
Q&A
Replies: 1 comment
-
SWR uses key as the resource identifier, not fetcher. If you have two Don’t do this: useSWR('data', fetcher1)
useSWR('data', fetcher2) It creates a conflict: is data supposed to be fetched with fetcher1 or fetcher2? The only explanation is they’re identical, and that’s what SWR does. It could use fetcher1 or fetcher2 based on the order, since they should be the same function. |
Beta Was this translation helpful? Give feedback.
0 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.
-
I was implementing likes feature in my blog post using swr and I used two separate fetcher, one for
/api/views/
and other for/api/likes
in their respective file and it seems that swr returns only one data as an object (either the likes or the views depending on which data is fetched first (I hope)).The problem got solved when I used a global fetcher and passed is through
SWRConfig
.So can anyone explain me what actually I did wrong.. or how swr works with the fetcher function ?
Beta Was this translation helpful? Give feedback.
All reactions