useSWRInfinite mutation #1290
Unanswered
tomaszczura
asked this question in
Q&A
Replies: 0 comments
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.
-
Hey! I have a question about using

useSWRInfinite
and mutating its state outside of a component. Take a look on my page draft:There are three components:
CompA
CompB
CompC
All of them uses different requests to get data.
CompA
andCompB
useuseSWRInfinite
to load their data, since there may be a lot of users. But they use different cache keys and different requests. Now, imagine I edit user'sUser B
name inCompC
(blue border) and save it asUser BB
. My question is - how can I update this user's name in all places? I found two problems here:mutate()
) inCompC
to fetch fresh data from the server, because it updates only the first page fromuseSWRInfinite
. I have to pass the new state tomutate
and usemutate(newUsers, false)
.CompA
I do not know the exact cache key (user may not be in first page), so I can't use importedmutate
.Currently we use
swr-mutate-many
library for this, so we have to know just a part of cache key and can pass updated state (e.g.mutateMany('*users*', newUsers)
). But is this the correct way of doing that? Do you have any existing solutions or you plan to implement something to make mutations inuseSWRInfinite
easier?Beta Was this translation helpful? Give feedback.
All reactions