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
Copy file name to clipboardExpand all lines: docs/src/pages/guides/migrating-to-react-query-4.md
+3-12Lines changed: 3 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -217,18 +217,9 @@ The `useQueries` hook now accepts an object with a `queries` prop as its input.
217
217
```
218
218
219
219
220
-
### Removed undocumented methods from the `queryClient`and `query`
220
+
### Removed undocumented methods from the `queryClient`, `query`and `mutation`
221
221
222
-
The methods `cancelMutatations` and `executeMutation` on the `QueryClient` were undocumented and unused internally, so we removed them. Since they were just wrappers around methods available on the `mutationCache`, you can still use the functionality.
The methods `cancelMutatations` and `executeMutation` on the `QueryClient` were undocumented and unused internally, so we removed them. Since it was just a wrapper around a method available on the `mutationCache`, you can still use the functionality of `executeMutation`
232
223
233
224
```diff
234
225
- executeMutation<
@@ -243,7 +234,7 @@ The methods `cancelMutatations` and `executeMutation` on the `QueryClient` were
243
234
- }
244
235
```
245
236
246
-
Additionally, `query.setDefaultOptions` was removed because it was also unused.
237
+
Additionally, `query.setDefaultOptions` was removed because it was also unused.`mutation.cancel` was removed because it didn't actually cancel the outgoing request.
Copy file name to clipboardExpand all lines: docs/src/pages/reference/QueryClient.md
+11-3Lines changed: 11 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -203,7 +203,7 @@ This distinction is more a "convenience" for ts devs that know which structure w
203
203
204
204
## `queryClient.setQueryData`
205
205
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**.
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**. To update multiple queries at once and match query keys partially, you need to use [`queryClient.setQueriesData`](#queryclientsetqueriesdata) instead.
207
207
208
208
> The difference between using `setQueryData` and `fetchQuery` is that `setQueryData` is sync and assumes that you already synchronously have the data available. If you need to fetch the data asynchronously, it's suggested that you either refetch the query key or use `fetchQuery` to handle the asynchronous fetch.
`setQueriesData` is a synchronous function that can be used to immediately update cached data of multiple queries. Only queries that match the passed queryKey or queryFilter will be updated - no new cache entries will be created. Under the hood, [`setQueryData`](#queryclientsetquerydata) is called for each query.
251
+
`setQueriesData` is a synchronous function that can be used to immediately update cached data of multiple queries by using filter function or partially matching the query key. Only queries that match the passed queryKey or queryFilter will be updated - no new cache entries will be created. Under the hood, [`setQueryData`](#queryclientsetquerydata) is called for each query.
> As stated in [`getQueryDefaults`](#queryclientgetquerydefaults), the order of registration of query defaults does matter.
498
+
> Since the **first** matching defaults are returned by `getQueryDefaults`, the registration should be made in the following order: from the **least generic key** to the **most generic one**. This way, in case of specific key, the first matching one would be the expected one.
499
+
494
500
## `queryClient.getMutationDefaults`
495
501
496
502
The `getMutationDefaults` method returns the default options which have been set for specific mutations:
@@ -516,6 +522,8 @@ function Component() {
516
522
-`mutationKey: string | unknown[]`
517
523
-`options: MutationOptions`
518
524
525
+
> Similar to [`setQueryDefaults`](#queryclientsetquerydefaults), the order of registration does matter here.
526
+
519
527
## `queryClient.getQueryCache`
520
528
521
529
The `getQueryCache` method returns the query cache this client is connected to.
// It is ok not having defaults, but it is error prone to have more than 1 default for a given key
555
+
if(matchingDefaults.length>1){
556
+
getLogger().error(
557
+
`[QueryClient] Several query defaults match with key '${JSON.stringify(
558
+
queryKey
559
+
)}'. The first matching query defaults are used. Please check how query defaults are registered. Order does matter here. cf. https://react-query.tanstack.com/reference/QueryClient#queryclientsetquerydefaults.`
// It is ok not having defaults, but it is error prone to have more than 1 default for a given key
600
+
if(matchingDefaults.length>1){
601
+
getLogger().error(
602
+
`[QueryClient] Several mutation defaults match with key '${JSON.stringify(
603
+
mutationKey
604
+
)}'. The first matching mutation defaults are used. Please check how mutation defaults are registered. Order does matter here. cf. https://react-query.tanstack.com/reference/QueryClient#queryclientsetmutationdefaults.`
0 commit comments