new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

TanStack Query · Reference · all subjects

queryclient methods: data access

5 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

queryClient.getQueryData

queryClient.getQueryData is a synchronous function that gets the cached data of a single query. It requires a queryKey parameter and returns the data for that query, or undefined if the query does not exist.

queryClient.getQueriesData

queryClient.getQueriesData is a synchronous function that gets cached data of multiple queries matching a queryKey or queryFilter. It returns [queryKey: QueryKey, data: TQueryFnData | undefined][], an array of tuples with query keys and their associated data. If no matches, returns empty array. The TData generic defaults to unknown when using filters.

queryClient.getQueryState

queryClient.getQueryState is a synchronous function that gets an existing query's state. It requires a queryKey parameter and returns the query state object, or undefined if the query does not exist. The state object contains properties like dataUpdatedAt.

Difference between getQueryState and getQueryData

queryClient.getQueryState returns the full query state object (containing properties like dataUpdatedAt), while queryClient.getQueryData returns only the data value of the query. getQueryState returns undefined if query doesn't exist; getQueryData also returns undefined if query doesn't exist.

queryClient.getQueryState returns dataUpdatedAt timestamp

The queryClient.getQueryState method returns the query state including a dataUpdatedAt timestamp property that indicates when the query data was last updated. This can be used to check if cached data is fresh enough for your needs.

Give your agent this brain

queryclient methods: data access — TanStack Query · Reference