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/guides/migrating-to-react-query-4.md
+37-3Lines changed: 37 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ title: Migrating to React Query 4
5
5
6
6
## Breaking Changes
7
7
8
+
v4 is a major version, so there are some breaking changes to be aware of:
9
+
8
10
### react-query is now @tanstack/react-query
9
11
10
12
```diff
@@ -15,6 +17,32 @@ title: Migrating to React Query 4
15
17
+ import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
16
18
```
17
19
20
+
#### Codemod
21
+
22
+
To make this migration easier, v4 comes with a codemod.
23
+
24
+
> The codemod is a best efforts attempt to help you migrate the breaking change. Please review the generated code thoroughly! Also, there are edge cases that cannot be found by the code mod, so please keep an eye on the log output.
25
+
26
+
You can easily apply it by using one (or both) of the following commands:
27
+
28
+
If you want to run it against `.js` or `.jsx` files, please use the command below:
Please note in the case of `TypeScript` you need to use `tsx` as the parser; otherwise, the codemod won't be applied properly!
41
+
42
+
**Note:** Applying the codemod might break your code formatting, so please don't forget to run `prettier` and/or `eslint` after you've applied the codemod!
43
+
44
+
**Note:** The codemod will _only_ change the imports - you still have to install the separate devtools package manually.
45
+
18
46
### Query Keys (and Mutation Keys) need to be an Array
19
47
20
48
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.
@@ -48,7 +76,7 @@ If you want to run it against `.ts` or `.tsx` files, please use the command belo
Please note in the case of `TypeScript` you need to use `tsx` as the parser otherwise, the codemod won't be applied properly!
79
+
Please note in the case of `TypeScript` you need to use `tsx` as the parser; otherwise, the codemod won't be applied properly!
52
80
53
81
**Note:** Applying the codemod might break your code formatting, so please don't forget to run `prettier` and/or `eslint` after you've applied the codemod!
### `persistQueryClient` and the corresponding persister plugins are no longer experimental and have been renamed
213
241
214
-
The plugins `createWebStoragePersistor` and `createAsyncStoragePersistor` have been renamed to [`createWebStoragePersister`](/plugins/createWebStoragePersister) 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.
242
+
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.
215
243
216
244
Since these plugins are no longer experimental, their import paths have also been updated:
217
245
@@ -221,7 +249,7 @@ Since these plugins are no longer experimental, their import paths have also bee
221
249
- import { createAsyncStoragePersistor } from 'react-query/createAsyncStoragePersistor-experimental'
222
250
223
251
+ import { persistQueryClient } from '@tanstack/react-query-persist-client'
224
-
+ import { createWebStoragePersister } from '@tanstack/query-sync-storage-persister'
252
+
+ import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
225
253
+ import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'
226
254
```
227
255
@@ -335,6 +363,12 @@ If you were importing anything from `'react-query/react'` directly in your proje
335
363
336
364
## New Features 🚀
337
365
366
+
v4 comes with an awesome set of new features:
367
+
368
+
### Support for React 18
369
+
370
+
React 18 was released earlier this year, and v4 now has first class support for it and the new concurrent features it brings.
371
+
338
372
### Proper offline support
339
373
340
374
In v3, React Query has always fired off queries and mutations, but then taken the assumption that if you want to retry it, you need to be connected to the internet. This has led to several confusing situations:
Copy file name to clipboardExpand all lines: docs/guides/mutations.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -151,7 +151,7 @@ useMutation(addTodo, {
151
151
})
152
152
```
153
153
154
-
You might find that you want to **trigger additional callbacks**than the ones defined on `useMutation` when calling `mutate`. This can be used to trigger component-specific side effects. To do that, you can provide any of the same callback options to the `mutate` function after your mutation variable. Supported overrides include: `onSuccess`, `onError` and `onSettled`. Please keep in mind that those additional callbacks won't run if your component unmounts _before_ the mutation finishes.
154
+
You might find that you want to **trigger additional callbacks**beyond the ones defined on `useMutation` when calling `mutate`. This can be used to trigger component-specific side effects. To do that, you can provide any of the same callback options to the `mutate` function after your mutation variable. Supported overrides include: `onSuccess`, `onError` and `onSettled`. Please keep in mind that those additional callbacks won't run if your component unmounts _before_ the mutation finishes.
155
155
156
156
```js
157
157
useMutation(addTodo, {
@@ -182,7 +182,7 @@ mutate(todo, {
182
182
### Consecutive mutations
183
183
There is a slight difference in handling `onSuccess`, `onError` and `onSettled` callbacks when it comes to consecutive mutations. When passed to the `mutate` function, they will be fired up only _once_ and only if the component is still mounted. This is due to the fact that mutation observer is removed and resubscribed every time when the `mutate` function is called. On the contrary, `useMutation` handlers execute for each `mutate` call.
184
184
185
-
> Be aware that most likely, `mutationFn` passed to `useMutation` is ansynchronous. In that case, the order in which mutations are fulfilled may differ from the order of `mutate` function calls.
185
+
> Be aware that most likely, `mutationFn` passed to `useMutation` is asynchronous. In that case, the order in which mutations are fulfilled may differ from the order of `mutate` function calls.
186
186
187
187
```js
188
188
useMutation(addTodo, {
@@ -286,7 +286,7 @@ If you persist offline mutations with the [persistQueryClient plugin](../plugins
286
286
This is a technical limitation. When persisting to an external storage, only the state of mutations is persisted, as functions cannot be serialized. After hydration, the component that triggeres the mutation might not be mounted, so calling `resumePausedMutations` might yield an error: `No mutationFn found`.
Copy file name to clipboardExpand all lines: docs/guides/ssr.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,7 +111,7 @@ As demonstrated, it's fine to prefetch some queries and let others fetch on the
111
111
112
112
There's a catch if you're using [Next.js' rewrites feature](https://nextjs.org/docs/api-reference/next.config.js/rewrites) together with [Automatic Static Optimization](https://nextjs.org/docs/advanced-features/automatic-static-optimization) or `getStaticProps`: It will cause a second hydration by React Query. That's because [Next.js needs to ensure that they parse the rewrites](https://nextjs.org/docs/api-reference/next.config.js/rewrites#rewrite-parameters) on the client and collect any params after hydration so that they can be provided in `router.query`.
113
113
114
-
The result is missing referential equality for all the hydration data, which for example triggers whereever your data is used as props of components or in the dependency array of `useEffect`s/`useMemo`s.
114
+
The result is missing referential equality for all the hydration data, which for example triggers wherever your data is used as props of components or in the dependency array of `useEffect`s/`useMemo`s.
115
115
116
116
## Using Other Frameworks or Custom SSR Frameworks
Copy file name to clipboardExpand all lines: docs/installation.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,11 +11,13 @@ or a good ol' `<script>` via
11
11
12
12
```bash
13
13
$ npm i @tanstack/react-query
14
+
# or
15
+
$ yarn add @tanstack/react-query
14
16
```
15
17
16
18
React Query is compatible with React v16.8+ and works with ReactDOM and React Native.
17
19
18
-
> Wanna give it a spin before you download? Try out the [simple](/docs/examples/simple) or [basic](/docs/examples/basic) examples!
20
+
> Wanna give it a spin before you download? Try out the [simple](/query/v4/docs/examples/react/simple) or [basic](/query/v4/docs/examples/react/basic) examples!
Copy file name to clipboardExpand all lines: docs/plugins/createAsyncStoragePersister.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ persistQueryClient({
39
39
40
40
## Retries
41
41
42
-
Retries work the same as for a [WebStoragePersister](./createWebStoragePersister), except that they can also be asynchronous. You can also use all the predefined retry handlers.
42
+
Retries work the same as for a [SyncStoragePersister](./createSyncStoragePersister), except that they can also be asynchronous. You can also use all the predefined retry handlers.
@@ -57,7 +57,7 @@ the persister `removeClient()` is called and the cache is immediately discarded.
57
57
### `persistQueryClientSave`
58
58
59
59
- Your query/mutation are [`dehydrated`](../reference/hydration#dehydrate) and stored by the persister you provided.
60
-
-`createWebStoragePersister` and `createAsyncStoragePersister` throttle this action to happen at most every 1 second to save on potentially expensive writes. Review their documentation to see how to customize their throttle timing.
60
+
-`createSyncStoragePersister` and `createAsyncStoragePersister` throttle this action to happen at most every 1 second to save on potentially expensive writes. Review their documentation to see how to customize their throttle timing.
61
61
62
62
You can use this to explicitly persist the cache at the moment(s) you choose.
63
63
@@ -181,8 +181,8 @@ For this use-case, you can use the `PersistQueryClientProvider`. It will make su
0 commit comments