Replies: 1 comment 1 reply
-
Instead of using import { mutate } from "swr";
mutate(key, currentData => /* update current data to add the new/updated item */. false); You can also get mutate from useSWR instead of importing it, in that case the key is already set for you, you need to pass the function as first argument. The false at the end prevents a revalidation to happen, if you don't pass it SWR will mutate the cached data and then request the whole data again to ensure it's correct, this is useful when doing optimistic UI, in your case you can disable it. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Say you have a large list of items that has been paginated using
useSWRPages
Currently, if we want to refresh the list, we have to call
revalidate
on every SWR which causes a lot of network trafficIn order to reduce traffic, APIs can typically provide filters to only retrieve elements that have been updated or created after a certain date, but I don't see a way to properly integrate that with SWR
My current solution is to have a second
useSWR
run next to myuseSWRPages
that polls that "recently updated data" endpoint, and to mutate the cache in the onSuccess ofuseSWR
, but that feels hacky (it has to remove some data from some pages, add some data to other pages, etc)I hope partial updates can become a first class citizen of the new pagination API given the high performance boost it would bring
Partial updates would also resolve this use-case
Beta Was this translation helpful? Give feedback.
All reactions