Query data becomes inactive when switching views (useQuery vs. useQueries with shared queryKey)
Hi,
I'm using TanStack Router together with TanStack Query, and I have a page that displays either a list of days or a calendar, depending on the view parameter.
- The list of days uses useQueries, since it fetches multiple requests.
- The calendar uses useQuery, as it loads a single dataset.
- Both use the same queryKey, since they fetch the same underlying data.
The issue is that when I first load the list of days, the data is correctly cached. However, when I switch to the calendar view, the queries from useQueries become inactive, and I can no longer access the cached data—I have to fetch everything again.
Is there a way to persist the data when switching between these two views? Should I be structuring my queries differently?
2 Replies
ambitious-aqua•9mo ago
seems like you don't have the queryKey set up correctly so that both views share the same key? show a minimal reproduction please
following-aqua•9mo ago
or they do not use a high enough
staleTime