Skip to content

Commit aa723a0

Browse files
authored
docs(examples): update examples to use react18 (#3466)
* tests: really assert that filtering works by checking that we never had two isFetchings * docs(examples): update react-scripts based examples to react18 and rq v4-beta * docs(examples): use react-query v4 in all examples * docs(examples): remove old version of persistence and use the dedicated provider instead * docs: use createRoot in the docs * docs(examples): fix import of createWebStoragePersister
1 parent 231b543 commit aa723a0

File tree

32 files changed

+111
-117
lines changed

32 files changed

+111
-117
lines changed

docs/src/pages/plugins/persistQueryClient.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ the persister `removeClient()` is called and the cache is immediately discarded.
5959

6060
### `persistQueryClientSave`
6161

62-
- Your query/mutation are [`dehydrated`](../reference/hydration#dehydrate) and stored by the persister you provided.
63-
- `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.
62+
- Your query/mutation are [`dehydrated`](../reference/hydration#dehydrate) and stored by the persister you provided.
63+
- `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.
6464

6565
You can use this to explicitly persist the cache at the moment(s) you choose.
6666

@@ -148,13 +148,13 @@ interface PersistQueryClientOptions {
148148
/** The options passed to the hydrate function
149149
* Not used on `persistQueryClientSave` or `persistQueryClientSubscribe` */
150150
hydrateOptions?: HydrateOptions
151-
/** The options passed to the dehydrate function
151+
/** The options passed to the dehydrate function
152152
* Not used on `persistQueryClientRestore` */
153153
dehydrateOptions?: DehydrateOptions
154154
}
155155
```
156156

157-
There are actually three interfaces available:
157+
There are actually three interfaces available:
158158
- `PersistedQueryClientSaveOptions` is used for `persistQueryClientSave` and `persistQueryClientSubscribe` (doesn't use `hydrateOptions`).
159159
- `PersistedQueryClientRestoreOptions` is used for `persistQueryClientRestore` (doesn't use `dehydrateOptions`).
160160
- `PersistQueryClientOptions` is used for `persistQueryClient`
@@ -175,7 +175,7 @@ persistQueryClient({
175175
})
176176

177177
// 🚨 happens at the same time as restoring
178-
ReactDOM.render(<App />, rootElement)
178+
ReactDOM.createRoot(rootElement).render(<App />)
179179
```
180180

181181
### PeristQueryClientProvider
@@ -199,14 +199,13 @@ const persister = createWebStoragePersister({
199199
storage: window.localStorage,
200200
})
201201

202-
ReactDOM.render(
202+
ReactDOM.createRoot(rootElement).render(
203203
<PersistQueryClientProvider
204204
client={queryClient}
205205
persistOptions={{ persister }}
206206
>
207207
<App />
208-
</PersistQueryClientProvider>,
209-
rootElement
208+
</PersistQueryClientProvider>
210209
)
211210
```
212211

examples/auto-refetching/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"next": "9.3.2",
1010
"react": "16.13.0",
1111
"react-dom": "16.13.0",
12-
"react-query": "^3.5.0"
12+
"react-query": "^4.0.0-beta.1"
1313
},
1414
"scripts": {
1515
"dev": "next",

examples/basic-graphql-request/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
"eject": "rescripts eject"
88
},
99
"dependencies": {
10-
"axios": "^0.21.1",
10+
"axios": "^0.26.1",
1111
"graphql": "^15.3.0",
1212
"graphql-request": "^3.1.0",
13-
"react": "^16.8.6",
14-
"react-dom": "^16.8.6",
15-
"react-query": "^3.5.0",
13+
"react": "^18.0.0",
14+
"react-dom": "^18.0.0",
15+
"react-query": "^4.0.0-beta.1",
1616
"react-scripts": "3.0.1",
1717
"stop-runaway-react-effects": "^1.2.0",
1818
"styled-components": "^4.3.2"

examples/basic-graphql-request/src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable jsx-a11y/anchor-is-valid */
22
import React from "react";
3-
import ReactDOM from "react-dom";
3+
import ReactDOM from "react-dom/client";
44
import {
55
useQuery,
66
useQueryClient,
@@ -40,7 +40,7 @@ function App() {
4040
}
4141

4242
function usePosts() {
43-
return useQuery(['posts'], async () => {
43+
return useQuery(["posts"], async () => {
4444
const {
4545
posts: { data },
4646
} = await request(
@@ -157,4 +157,4 @@ function Post({ postId, setPostId }) {
157157
}
158158

159159
const rootElement = document.getElementById("root");
160-
ReactDOM.render(<App />, rootElement);
160+
ReactDOM.createRoot(rootElement).render(<App />);

examples/basic-typescript/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"eject": "rescripts eject"
88
},
99
"dependencies": {
10-
"axios": "^0.21.1",
10+
"axios": "^0.26.1",
1111
"broadcast-channel": "^3.4.1",
12-
"react": "^17.0.2",
13-
"react-dom": "^17.0.2",
14-
"react-query": "^3.13.3",
12+
"react": "^18.0.0",
13+
"react-dom": "^18.0.0",
14+
"react-query": "^4.0.0-beta.1",
1515
"react-scripts": "3.0.1",
1616
"stop-runaway-react-effects": "^1.2.0",
1717
"styled-components": "^4.3.2",

examples/basic-typescript/src/index.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
/* eslint-disable jsx-a11y/anchor-is-valid */
22
import * as React from "react";
3-
import ReactDOM from "react-dom";
3+
import ReactDOM from "react-dom/client";
44
import axios from "axios";
5-
import {
6-
useQuery,
7-
useQueryClient,
8-
QueryClient,
9-
QueryClientProvider,
10-
} from "react-query";
5+
import { useQuery, useQueryClient, QueryClient } from "react-query";
6+
import { PersistQueryClientProvider } from "react-query/persistQueryClient";
7+
import { createWebStoragePersister } from "react-query/createWebStoragePersister";
118
import { ReactQueryDevtools } from "react-query/devtools";
129

13-
const queryClient = new QueryClient();
10+
const queryClient = new QueryClient({
11+
defaultOptions: {
12+
queries: {
13+
cacheTime: 1000 * 60 * 60 * 24, // 24 hours
14+
},
15+
},
16+
});
17+
18+
const persister = createWebStoragePersister({
19+
storage: window.localStorage,
20+
});
1421

1522
type Post = {
1623
id: number;
@@ -128,7 +135,10 @@ function App() {
128135
const [postId, setPostId] = React.useState(-1);
129136

130137
return (
131-
<QueryClientProvider client={queryClient}>
138+
<PersistQueryClientProvider
139+
client={queryClient}
140+
persistOptions={{ persister }}
141+
>
132142
<p>
133143
As you visit the posts below, you will notice them in a loading state
134144
the first time you load them. However, after you return to this list and
@@ -145,9 +155,9 @@ function App() {
145155
<Posts setPostId={setPostId} />
146156
)}
147157
<ReactQueryDevtools initialIsOpen />
148-
</QueryClientProvider>
158+
</PersistQueryClientProvider>
149159
);
150160
}
151161

152162
const rootElement = document.getElementById("root");
153-
ReactDOM.render(<App />, rootElement);
163+
ReactDOM.createRoot(rootElement).render(<App />);

examples/basic/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"dependencies": {
1010
"axios": "^0.21.1",
1111
"broadcast-channel": "^3.4.1",
12-
"react": "^16.8.6",
13-
"react-dom": "^16.8.6",
14-
"react-query": "^3.5.0",
12+
"react": "^18.0.0",
13+
"react-dom": "^18.0.0",
14+
"react-query": "^4.0.0-beta.1",
1515
"react-scripts": "3.0.1",
1616
"stop-runaway-react-effects": "^1.2.0",
1717
"styled-components": "^4.3.2"

examples/basic/src/index.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable jsx-a11y/anchor-is-valid */
22
import React from "react";
3-
import ReactDOM from "react-dom";
3+
import ReactDOM from "react-dom/client";
44
import axios from "axios";
55
import {
66
useQuery,
@@ -9,23 +9,8 @@ import {
99
QueryClientProvider,
1010
} from "react-query";
1111
import { ReactQueryDevtools } from "react-query/devtools";
12-
import { persistQueryClient } from 'react-query/persistQueryClient';
13-
import { createWebStoragePersister } from 'react-query/createWebStoragePersister'
1412

15-
const queryClient = new QueryClient({
16-
defaultOptions: {
17-
queries: {
18-
cacheTime: 1000 * 60 * 60 * 24, // 24 hours
19-
},
20-
},
21-
})
22-
23-
const localStoragePersister = createWebStoragePersister({storage: window.localStorage})
24-
25-
persistQueryClient({
26-
queryClient,
27-
persister: localStoragePersister,
28-
})
13+
const queryClient = new QueryClient();
2914

3015
function App() {
3116
const [postId, setPostId] = React.useState(-1);
@@ -146,4 +131,4 @@ function Post({ postId, setPostId }) {
146131
}
147132

148133
const rootElement = document.getElementById("root");
149-
ReactDOM.render(<App />, rootElement);
134+
ReactDOM.createRoot(rootElement).render(<App />);

examples/custom-hooks/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"eject": "rescripts eject"
88
},
99
"dependencies": {
10-
"axios": "^0.21.1",
11-
"react": "^16.8.6",
12-
"react-dom": "^16.8.6",
13-
"react-query": "^3.5.0",
10+
"axios": "^0.26.1",
11+
"react": "^18.0.0",
12+
"react-dom": "^18.0.0",
13+
"react-query": "^4.0.0-beta.1",
1414
"react-scripts": "3.0.1",
1515
"stop-runaway-react-effects": "^1.2.0",
1616
"styled-components": "^4.3.2"

examples/custom-hooks/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable jsx-a11y/anchor-is-valid */
22
import React from "react";
3-
import ReactDOM from "react-dom";
3+
import ReactDOM from "react-dom/client";
44
import { QueryClient, QueryClientProvider, useQueryClient } from "react-query";
55
import { ReactQueryDevtools } from "react-query/devtools";
66

@@ -102,4 +102,4 @@ function Post({ postId, setPostId }) {
102102
}
103103

104104
const rootElement = document.getElementById("root");
105-
ReactDOM.render(<App />, rootElement);
105+
ReactDOM.createRoot(rootElement).render(<App />);

0 commit comments

Comments
 (0)