TanStackT
TanStack2y ago
10 replies
ill-bronze

useQueries understanding which query's response updated?

The useQueries hook returns an array with all the query results. The order returned is the same as the input order.

How can we distinguish what changed? For example, I have 2 queries, imagine one takes 5x longer than the other one. The useQueries hook keeps rerending the component because the second query is still loading.
Query1: L L L L L S
Query2: L L L L L L L L L L L L L L L L L L L S

In my case we do an expensive data transformation once the data is received, but since useQueries keeps rerendering, how do I detect the change? I know I can do useMemo to memoize the the data transform, however, the data fetched can be 10s of MBs so I want to be really careful.

Another thing I tried was to set some flag but this fails coz the data can be refetched (either cache invalidation or other configuration). So the flag works for first time, but the second time it fetches data, I have to end up building complex state machine which I assume useQuery is also doing
Was this page helpful?