Managing Consistent Favorited State Across Paginated Searches with React Query #5918
-
|
I have the following scenario: I have a search page with filters that query for a list of companies (based on filters). Now users can mark a single or multiple companies as "favorites". This means I have to update the cache for the current page, but previous pages (cache entries) that the user searched for might also contain the same company. If the user now goes back to the previous search, he will get the result from the cache and Apple won't be marked as favorite anymore. How would you suggest approaching this? I realize I can invalidate all searches when the user marks something as favorite but this is very inefficient |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
why is that inefficient ? You would instantly refetch the currently used query, and mark all others as stale. If you go back to a different view that has data marked as stale, it would refetch to get the latest data for that search. |
Beta Was this translation helpful? Give feedback.
you can of course write to the cache manually. If they all have the same data structure, you can do this in one go with
queryClient.setQueriesData.