T
TanStack2y ago
mute-gold

Infinit Query avoid useless refetch when part of the list is updated

Hello I am working with infinit query to fetch a list of group. when I access the detail of a group I need to refetch the detail even if the data is present in the list of the infinit query. When I update a group I need to refetch the detail and the infinit query. So I wonder if there is a way to avoid all those useless refetch. For example: my infinit query is store with key: [groups] each detail is store with key: [groups, :id] when I access a group detail I query [groups, 1] when I update the group 1 (manual or refresh) I want the the key [groups] to be up to date with the latest version of [groups, 1] without the need of requering [groups]
3 Replies
robust-apricot
robust-apricot2y ago
Updates from Mutation Responses | TanStack Query Docs
When dealing with mutations that update objects on the server, it's common for the new object to be automatically returned in the response of the mutation. Instead of refetching any queries for that item and wasting a network call for data we already have, we can take advantage of the object returned by the mutation function and update the exis...
mute-gold
mute-goldOP2y ago
yes but how do I write to infinit query
robust-apricot
robust-apricot2y ago
Same way, you just need to adhere to the structure of { pages, pageParams }

Did you find this page helpful?