Batching queryCache.setQueryData\ #1467
-
Hello, what I am doing is prefetching a whole group of items with react-query. After I prefetch my data, I am setting each individual item also in my cache by the item's unique key. I am doing this so that when I go to an individual item's page, I can start fetching that particular item right away with a useQuery while all the items are loading the background. Also so that I can refetch just individual items and not refetching all the items every time a change is made. In my function I am looping over all the items and then calling queryCache,setQueryCache(...) to set the cache with my now local data for each item. I then loop over part of the items to set a different queryCache. What I have noticed is that when I start prefetching a lot of these items, then my app starts to freeze up. Looking at the burn down chart, it seems like this is due to react-query's "dispatch" being called most likely to update my query cache. Is there a way that I can wrap my setQueryCache calls in a batch so that there is only one dispatch call being made? Thank you for any and all help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Although currently not documented, I think you should be able to do this: import { notifyManager } from "react-query"
notifyManager.batch(() => {
queryClient.setQueryData(...)
queryClient.setQueryData(...)
}) |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
Here is my burn down chart using that react "batch". UI is most definitely being blocked during this time.