Replies: 3 comments 7 replies
-
The refetching of infinite query will always refetch all pages. But I’ve heard the need for a more granular refetch often now. Do you have a proposal how that api could look? |
Beta Was this translation helpful? Give feedback.
-
Came across the same issue. Gonna start a new reply for a different soltion than @TkDodo proposed. Basically, I don't think the invalidation implementation is the problem as much as there's a a missing mapping between queries. If we can define query relationships, whether in the query or client or cache, we can use that to auto follow invalidations/cache changes. Something like this: interface Data {
id: string,
name: string
}
fetchList: () => Data[]
useInfiniteQuery('listQuery', fetchList, {
mapping: [
(listData) => {
return listData.flatMap(data => {
key: ['itemQuery', data.id],
getData: (listData) => listData.flat().find(item => item.id === data.id),
setData: (itemData:Data) => // find the item in listData, change it and return the new Data[][]
}
)
}
]
}) really quick mock up, its basically some sort of two way binding: when this query is fetched, update that query data, and vice versa, so you always have the freshest data. I actually kinda do this but just one way right now - I iterate on the list and setQueryData(['todos', todoId]) |
Beta Was this translation helpful? Give feedback.
-
have a look at the PR I've opened and let me know what you think: #2557 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
How can I invalidate a single item when working with useInfiniteQuery? Here is an example that demonstrates what I am trying to accomplish.
Let`s say I have a list of members and each member has a follow button. When I press on to follow button, there is a separate call to the server to mark that the given user is following another user. After this, I have to invalidate the entire infinite query to reflect the state of following for a single member. That means I might have a lot of users loaded in infinite query and I need to re-fetch all the items that were already loaded just to reflect the change for one item.
I know I can change the value in queryClient.setQueryData when follow fetch returns success but without following this with invalidation and fetch of a member, I am basically going out of sync with the server and relying on local data.
Any possible ways to address this issue?
Here is a reference UI photo just in case if it will be helpful.
Beta Was this translation helpful? Give feedback.
All reactions