In what situations the `data` content gets reset?
I'm trying to use Query to handle an analytics dashboard. The query key is made of the url plus query params, the latter contains a start and end property. Every 30 seconds the time filter gets updated to use the latest timestamp.
What happens is that React Query re-triggers the
isPending
because, after some debugging, I found out that at every call the content of data
goes undefined even though there was some stuff before. I've tried to check for some unwanted rerender but everything looks fine.
In your experience, when does the data
content gets reset?3 Replies
correct-apricot•2y ago
I guess the start and end property are part of the queryKey (as they should), so you'll get a new cache entry, where you have no data yet, hence the pending state.
have a look at
placeholderData
(in v5): https://tanstack.com/query/latest/docs/react/guides/paginated-queries#better-paginated-queries-with-placeholderdataPaginated / Lagged Queries | TanStack Query Docs
Rendering paginated data is a very common UI pattern and in TanStack Query, it "just works" by including the page information in the query key:
extended-yellowOP•2y ago
Ok so if I understand it correctly there is a data content for each different queryKey? Thanks a lot, the example you linked solved the issue.
correct-apricot•2y ago
yep 🙂