Update all related cache #3631
-
Hi, I have a question about keeping all the data in the cache up to date. Best to show it in an example. Let's say we have personal feed. This feed is made up of FeedItems. Now let's say there is another FeedList. As you can see these lists have Now let's say we have a detailPage of sorts that we can get by clicking on the FeedItem. In case we fetch the lists in order Ideally fetching |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can also manually update all feeds in the onSuccess callback if one of the feeds fetches with If you're looking for something more automatic, you basically want something like a normalized cache, where you also need a schema, which is something that react-query does not require, thus it does not provide a normalized cache. GraphQL specific solutions are good at doing that (apollo, urql). |
Beta Was this translation helpful? Give feedback.
invalidateQueries
will make sure that every feed that matches the passed key is either refetched immediately (if used on the screen), or marked as stale so that it will be refetched when it is used the next time. So if you invalidate all list, and then go back to list1, that one will be refetched. If you go to list2, that will be refetched.You can also manually update all feeds in the onSuccess callback if one of the feeds fetches with
queryClient.setQueriesData
, but I don't think it's necessary.If you're looking for something more automatic, you basically want something like a normalized cache, where you also need a schema, which is something that react-query does not require, thus it …