You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -175,6 +176,31 @@ const data = queryClient.getQueryData(queryKey)
175
176
-`data: TData | undefined`
176
177
- The data for the cached query, or `undefined` if the query does not exist.
177
178
179
+
## `queryClient.getQueriesData`
180
+
181
+
`getQueriesData` is a synchronous function that can be used to get the cached data of multiple queries. Only queries that match the passed queryKey or queryFilter will be returned. If there are no matching queries, an empty array will be returned.
- if a queryKey is passed as the argument, the data with queryKeys fuzzily matching this param will be returned
191
+
- if a filter is passed, the data with queryKeys matching the filter will be returned
192
+
193
+
**Returns**
194
+
195
+
-`[queryKey:QueryKey, data:TData | unknown][]`
196
+
- An array of tuples for the matched query keys, or `[]` if there are no matches. The tuples are the query key and its associated data.
197
+
198
+
**Caveats**
199
+
200
+
Because the returned data in each tuple can be of varying structures (i.e. using a filter to return "active" queries can return different data types), the `TData` generic defaults to `unknown`. If you provide a more specific type to `TData` it is assumed that you are certain each tuple's data entry is all the same type.
201
+
202
+
This distinction is more a "convenience" for ts devs that know which structure will be returned.
203
+
178
204
## `queryClient.setQueryData`
179
205
180
206
`setQueryData` is a synchronous function that can be used to immediately update a query's cached data. If the query does not exist, it will be created. **If the query is not utilized by a query hook in the default `cacheTime` of 5 minutes, the query will be garbage collected**.
0 commit comments