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
@@ -58,15 +58,15 @@ Please note in the case of `TypeScript` you need to use `tsx` as the parser; oth
58
58
59
59
### Query Keys (and Mutation Keys) need to be an Array
60
60
61
-
In v3, Query and Mutation Keys could be a String or an Array. Internally, React Query has always worked with Array Keys only, and we've sometimes exposed this to consumers. For example, in the `queryFn`, you would always get the key as an Array to make working with [Default Query Functions](./guides/default-query-function) easier.
61
+
In v3, Query and Mutation Keys could be a String or an Array. Internally, React Query has always worked with Array Keys only, and we've sometimes exposed this to consumers. For example, in the `queryFn`, you would always get the key as an Array to make working with [Default Query Functions](../default-query-function) easier.
62
62
63
-
However, we have not followed this concept through to all apis. For example, when using the `predicate` function on [Query Filters](./guides/filters) you would get the raw Query Key. This makes it difficult to work with such functions if you use Query Keys that are mixed Arrays and Strings. The same was true when using global callbacks.
63
+
However, we have not followed this concept through to all apis. For example, when using the `predicate` function on [Query Filters](../filters) you would get the raw Query Key. This makes it difficult to work with such functions if you use Query Keys that are mixed Arrays and Strings. The same was true when using global callbacks.
64
64
65
65
To streamline all apis, we've decided to make all keys Arrays only:
66
66
67
-
```diff
68
-
-useQuery('todos', fetchTodos)
69
-
+useQuery(['todos'], fetchTodos)
67
+
```tsx
68
+
;-useQuery('todos', fetchTodos)+// [!code --]
69
+
useQuery(['todos'], fetchTodos)// [!code ++]
70
70
```
71
71
72
72
#### Codemod
@@ -100,41 +100,49 @@ Please note in the case of `TypeScript` you need to use `tsx` as the parser; oth
100
100
101
101
### The idle state has been removed
102
102
103
-
With the introduction of the new [fetchStatus](./guides/queries#fetchstatus) for better offline support, the `idle` state became irrelevant, because `fetchStatus: 'idle'` captures the same state better. For more information, please read [Why two different states](./guides/queries#why-two-different-states).
103
+
With the introduction of the new [fetchStatus](../queries#fetchstatus) for better offline support, the `idle` state became irrelevant, because `fetchStatus: 'idle'` captures the same state better. For more information, please read [Why two different states](../queries#why-two-different-states).
104
104
105
105
This will mostly affect `disabled` queries that don't have any `data` yet, as those were in `idle` state before:
106
106
107
-
```diff
108
-
- status: 'idle'
109
-
+ status: 'loading'
110
-
+ fetchStatus: 'idle'
107
+
```tsx
108
+
-status: 'idle'// [!code --]
109
+
+status: 'loading'// [!code ++]
110
+
+fetchStatus: 'idle'// [!code ++]
111
111
```
112
112
113
-
Also, have a look at [the guide on dependent queries](./guides/dependent-queries)
113
+
Also, have a look at [the guide on dependent queries](../dependent-queries)
114
114
115
115
#### disabled queries
116
116
117
117
Due to this change, disabled queries (even temporarily disabled ones) will start in `loading` state. To make migration easier, especially for having a good flag to know when to display a loading spinner, you can check for `isInitialLoading` instead of `isLoading`:
118
118
119
-
```diff
120
-
-isLoading
121
-
+isInitialLoading
119
+
```tsx
120
+
;-isLoading+// [!code --]
121
+
isInitialLoading// [!code ++]
122
122
```
123
123
124
-
See also the guide on [disabling queries](./guides/disabling-queries#isInitialLoading)
124
+
See also the guide on [disabling queries](../disabling-queries#isInitialLoading)
125
125
126
126
### new API for `useQueries`
127
127
128
128
The `useQueries` hook now accepts an object with a `queries` prop as its input. The value of the `queries` prop is an array of queries (this array is identical to what was passed into `useQueries` in v3).
### Undefined is an illegal cache value for successful queries
136
144
137
-
In order to make bailing out of updates possible by returning `undefined`, we had to make `undefined` an illegal cache value. This is in-line with other concepts of react-query, for example, returning `undefined` from the [initialData function](guides/initial-query-data#initial-data-function) will also _not_ set data.
145
+
In order to make bailing out of updates possible by returning `undefined`, we had to make `undefined` an illegal cache value. This is in-line with other concepts of react-query, for example, returning `undefined` from the [initialData function](../initial-query-data#initial-data-function) will also _not_ set data.
138
146
139
147
Further, it is an easy bug to produce `Promise<void>` by adding logging in the queryFn:
140
148
@@ -148,7 +156,7 @@ This is now disallowed on type level; at runtime, `undefined` will be transforme
148
156
149
157
### Queries and mutations, per default, need network connection to run
150
158
151
-
Please read the [New Features announcement](#proper-offline-support) about online / offline support, and also the dedicated page about [Network mode](./guides/network-mode)
159
+
Please read the [New Features announcement](#proper-offline-support) about online / offline support, and also the dedicated page about [Network mode](../network-mode)
152
160
153
161
Even though React Query is an Async State Manager that can be used for anything that produces a Promise, it is most often used for data fetching in combination with data fetching libraries. That is why, per default, queries and mutations will be `paused` if there is no network connection. If you want to opt-in to the previous behavior, you can globally set `networkMode: offlineFirst` for both queries and mutations:
A [query filter](./guides/filters) is an object with certain conditions to match a query. Historically, the filter options have mostly been a combination of boolean flags. However, combining those flags can lead to impossible states. Specifically:
220
+
A [query filter](../filters) is an object with certain conditions to match a query. Historically, the filter options have mostly been a combination of boolean flags. However, combining those flags can lead to impossible states. Specifically:
213
221
214
222
```
215
223
active?: boolean
@@ -224,17 +232,17 @@ Those flags don't work well when used together, because they are mutually exclus
224
232
225
233
With v4, those filters have been combined into a single filter to better show the intent:
226
234
227
-
```diff
228
-
- active?: boolean
229
-
- inactive?: boolean
230
-
+ type?: 'active' | 'inactive' | 'all'
235
+
```tsx
236
+
-active?:boolean// [!code --]
237
+
-inactive?:boolean// [!code --]
238
+
+type?:'active'|'inactive'|'all'// [!code ++]
231
239
```
232
240
233
241
The filter defaults to `all`, and you can choose to only match `active` or `inactive` queries.
234
242
235
243
#### refetchActive / refetchInactive
236
244
237
-
[queryClient.invalidateQueries](./reference/QueryClient#queryclientinvalidatequeries) had two additional, similar flags:
245
+
[queryClient.invalidateQueries](../../../../reference/QueryClient/#queryclientinvalidatequeries) had two additional, similar flags:
238
246
239
247
```
240
248
refetchActive: Boolean
@@ -249,10 +257,10 @@ refetchInactive: Boolean
249
257
250
258
For the same reason, those have also been combined:
This flag defaults to `active` because `refetchActive` defaulted to `true`. This means we also need a way to tell `invalidateQueries` to not refetch at all, which is why a fourth option (`none`) is also allowed here.
### `persistQueryClient` and the corresponding persister plugins are no longer experimental and have been renamed
274
282
275
-
The plugins `createWebStoragePersistor` and `createAsyncStoragePersistor` have been renamed to [`createSyncStoragePersister`](./plugins/createSyncStoragePersister) and [`createAsyncStoragePersister`](./plugins/createAsyncStoragePersister) respectively. The interface `Persistor` in `persistQueryClient` has also been renamed to `Persister`. Checkout [this stackexchange](https://english.stackexchange.com/questions/206893/persister-or-persistor) for the motivation of this change.
283
+
The plugins `createWebStoragePersistor` and `createAsyncStoragePersistor` have been renamed to [`createSyncStoragePersister`](../../plugins/createSyncStoragePersister) and [`createAsyncStoragePersister`](../../plugins/createAsyncStoragePersister) respectively. The interface `Persistor` in `persistQueryClient` has also been renamed to `Persister`. Checkout [this stackexchange](https://english.stackexchange.com/questions/206893/persister-or-persistor) for the motivation of this change.
276
284
277
285
Since these plugins are no longer experimental, their import paths have also been updated:
278
286
279
-
```diff
280
-
- import { persistQueryClient } from 'react-query/persistQueryClient-experimental'
281
-
- import { createWebStoragePersistor } from 'react-query/createWebStoragePersistor-experimental'
282
-
- import { createAsyncStoragePersistor } from 'react-query/createAsyncStoragePersistor-experimental'
### The `cancel` method on promises is no longer supported
290
298
291
-
The [old `cancel` method](./guides/query-cancellation#old-cancel-function) that allowed you to define a `cancel` function on promises, which was then used by the library to support query cancellation, has been removed. We recommend to use the [newer API](./guides/query-cancellation) (introduced with v3.30.0) for query cancellation that uses the [`AbortController` API](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) internally and provides you with an [`AbortSignal` instance](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) for your query function to support query cancellation.
299
+
The [old `cancel` method](../query-cancellation#old-cancel-function) that allowed you to define a `cancel` function on promises, which was then used by the library to support query cancellation, has been removed. We recommend to use the [newer API](../query-cancellation) (introduced with v3.30.0) for query cancellation that uses the [`AbortController` API](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) internally and provides you with an [`AbortSignal` instance](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) for your query function to support query cancellation.
292
300
293
301
### TypeScript
294
302
295
303
Types now require using TypeScript v4.1 or greater
296
304
297
305
### Supported Browsers
298
306
299
-
As of v4, React Query is optimized for modern browsers. We have updated our browserslist to produce a more modern, performant and smaller bundle. You can read about the requirements [here](./installation#requirements).
307
+
As of v4, React Query is optimized for modern browsers. We have updated our browserslist to produce a more modern, performant and smaller bundle. You can read about the requirements [here](../../installation#requirements).
300
308
301
309
### `setLogger` is removed
302
310
303
311
It was possible to change the logger globally by calling `setLogger`. In v4, that function is replaced with an optional field when creating a `QueryClient`.
304
312
305
-
```diff
306
-
- import { QueryClient, setLogger } from 'react-query';
307
-
+ import { QueryClient } from '@tanstack/react-query';
### No _default_ manual Garbage Collection server-side
@@ -334,13 +342,13 @@ Subscribing manually to the `QueryCache` has always given you a `QueryCacheNotif
334
342
335
343
#### QueryCacheNotifyEvent
336
344
337
-
```diff
338
-
- type: 'queryAdded'
339
-
+ type: 'added'
340
-
- type: 'queryRemoved'
341
-
+ type: 'removed'
342
-
- type: 'queryUpdated'
343
-
+ type: 'updated'
345
+
```tsx
346
+
-type: 'queryAdded'// [!code --]
347
+
+type: 'added'// [!code ++]
348
+
-type: 'queryRemoved'// [!code --]
349
+
+type: 'removed'// [!code ++]
350
+
-type: 'queryUpdated'// [!code --]
351
+
+type: 'updated'// [!code ++]
344
352
```
345
353
346
354
#### MutationCacheNotifyEvent
@@ -353,26 +361,26 @@ The `MutationCacheNotifyEvent` uses the same types as the `QueryCacheNotifyEvent
353
361
354
362
With version [3.22.0](https://github.com/tannerlinsley/react-query/releases/tag/v3.22.0), hydration utilities moved into the React Query core. With v3, you could still use the old exports from `react-query/hydration`, but these exports have been removed with v4.
355
363
356
-
```diff
357
-
- import { dehydrate, hydrate, useHydrate, Hydrate } from 'react-query/hydration'
358
-
+ import { dehydrate, hydrate, useHydrate, Hydrate } from '@tanstack/react-query'
### Removed undocumented methods from the `queryClient`, `query` and `mutation`
362
370
363
371
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`
Additionally, `query.setDefaultOptions` was removed because it was also unused. `mutation.cancel` was removed because it didn't actually cancel the outgoing request.
@@ -389,9 +397,9 @@ With the renamed directory this no longer is an issue.
389
397
390
398
If you were importing anything from `'react-query/react'` directly in your project (as opposed to just `'react-query'`), then you need to update your imports:
391
399
392
-
```diff
393
-
- import { QueryClientProvider } from 'react-query/react';
394
-
+ import { QueryClientProvider } from '@tanstack/react-query/reactjs';
@@ -411,15 +419,15 @@ In v3, React Query has always fired off queries and mutations, but then taken th
411
419
- You are offline and want to fire off a query that doesn't necessarily need network connection (because you _can_ use React Query for something other than data fetching), but it fails for some other reason. That query will now be paused until you go online again.
412
420
- Window focus refetching didn't do anything at all if you were offline.
413
421
414
-
With v4, React Query introduces a new `networkMode` to tackle all these issues. Please read the dedicated page about the new [Network mode](./guides/network-mode) for more information.
422
+
With v4, React Query introduces a new `networkMode` to tackle all these issues. Please read the dedicated page about the new [Network mode](../network-mode) for more information.
415
423
416
424
### Tracked Queries per default
417
425
418
426
React Query defaults to "tracking" query properties, which should give you a nice boost in render optimization. The feature has existed since [v3.6.0](https://github.com/tannerlinsley/react-query/releases/tag/v3.6.0) and has now become the default behavior with v4.
419
427
420
428
### Bailing out of updates with setQueryData
421
429
422
-
When using the [functional updater form of setQueryData](./reference/QueryClient#queryclientsetquerydata), you can now bail out of the update by returning `undefined`. This is helpful if `undefined` is given to you as `previousValue`, which means that currently, no cached entry exists and you don't want to / cannot create one, like in the example of toggling a todo:
430
+
When using the [functional updater form of setQueryData](../../../../reference/QueryClient/#queryclientsetquerydata), you can now bail out of the update by returning `undefined`. This is helpful if `undefined` is given to you as `previousValue`, which means that currently, no cached entry exists and you don't want to / cannot create one, like in the example of toggling a todo:
0 commit comments