Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(examples): update examples to use react18 #3466

Merged
merged 6 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions docs/src/pages/plugins/persistQueryClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ the persister `removeClient()` is called and the cache is immediately discarded.

### `persistQueryClientSave`

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

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

Expand Down Expand Up @@ -148,13 +148,13 @@ interface PersistQueryClientOptions {
/** The options passed to the hydrate function
* Not used on `persistQueryClientSave` or `persistQueryClientSubscribe` */
hydrateOptions?: HydrateOptions
/** The options passed to the dehydrate function
/** The options passed to the dehydrate function
* Not used on `persistQueryClientRestore` */
dehydrateOptions?: DehydrateOptions
}
```

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

// 🚨 happens at the same time as restoring
ReactDOM.render(<App />, rootElement)
ReactDOM.createRoot(rootElement).render(<App />)
```

### PeristQueryClientProvider
Expand All @@ -199,14 +199,13 @@ const persister = createWebStoragePersister({
storage: window.localStorage,
})

ReactDOM.render(
ReactDOM.createRoot(rootElement).render(
<PersistQueryClientProvider
client={queryClient}
persistOptions={{ persister }}
>
<App />
</PersistQueryClientProvider>,
rootElement
</PersistQueryClientProvider>
)
```

Expand Down
2 changes: 1 addition & 1 deletion examples/auto-refetching/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"next": "9.3.2",
"react": "16.13.0",
"react-dom": "16.13.0",
"react-query": "^3.5.0"
"react-query": "^4.0.0-beta.1"
},
"scripts": {
"dev": "next",
Expand Down
8 changes: 4 additions & 4 deletions examples/basic-graphql-request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"eject": "rescripts eject"
},
"dependencies": {
"axios": "^0.21.1",
"axios": "^0.26.1",
"graphql": "^15.3.0",
"graphql-request": "^3.1.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-query": "^3.5.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-query": "^4.0.0-beta.1",
"react-scripts": "3.0.1",
"stop-runaway-react-effects": "^1.2.0",
"styled-components": "^4.3.2"
Expand Down
6 changes: 3 additions & 3 deletions examples/basic-graphql-request/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
import React from "react";
import ReactDOM from "react-dom";
import ReactDOM from "react-dom/client";
import {
useQuery,
useQueryClient,
Expand Down Expand Up @@ -40,7 +40,7 @@ function App() {
}

function usePosts() {
return useQuery(['posts'], async () => {
return useQuery(["posts"], async () => {
const {
posts: { data },
} = await request(
Expand Down Expand Up @@ -157,4 +157,4 @@ function Post({ postId, setPostId }) {
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
ReactDOM.createRoot(rootElement).render(<App />);
8 changes: 4 additions & 4 deletions examples/basic-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"eject": "rescripts eject"
},
"dependencies": {
"axios": "^0.21.1",
"axios": "^0.26.1",
"broadcast-channel": "^3.4.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-query": "^3.13.3",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-query": "^4.0.0-beta.1",
"react-scripts": "3.0.1",
"stop-runaway-react-effects": "^1.2.0",
"styled-components": "^4.3.2",
Expand Down
32 changes: 21 additions & 11 deletions examples/basic-typescript/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
import * as React from "react";
import ReactDOM from "react-dom";
import ReactDOM from "react-dom/client";
import axios from "axios";
import {
useQuery,
useQueryClient,
QueryClient,
QueryClientProvider,
} from "react-query";
import { useQuery, useQueryClient, QueryClient } from "react-query";
import { PersistQueryClientProvider } from "react-query/persistQueryClient";
import { createWebStoragePersister } from "react-query/createWebStoragePersister";
import { ReactQueryDevtools } from "react-query/devtools";

const queryClient = new QueryClient();
const queryClient = new QueryClient({
defaultOptions: {
queries: {
cacheTime: 1000 * 60 * 60 * 24, // 24 hours
},
},
});

const persister = createWebStoragePersister({
storage: window.localStorage,
});

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

return (
<QueryClientProvider client={queryClient}>
<PersistQueryClientProvider
client={queryClient}
persistOptions={{ persister }}
>
<p>
As you visit the posts below, you will notice them in a loading state
the first time you load them. However, after you return to this list and
Expand All @@ -145,9 +155,9 @@ function App() {
<Posts setPostId={setPostId} />
)}
<ReactQueryDevtools initialIsOpen />
</QueryClientProvider>
</PersistQueryClientProvider>
);
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
ReactDOM.createRoot(rootElement).render(<App />);
6 changes: 3 additions & 3 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"dependencies": {
"axios": "^0.21.1",
"broadcast-channel": "^3.4.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-query": "^3.5.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-query": "^4.0.0-beta.1",
"react-scripts": "3.0.1",
"stop-runaway-react-effects": "^1.2.0",
"styled-components": "^4.3.2"
Expand Down
21 changes: 3 additions & 18 deletions examples/basic/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
import React from "react";
import ReactDOM from "react-dom";
import ReactDOM from "react-dom/client";
import axios from "axios";
import {
useQuery,
Expand All @@ -9,23 +9,8 @@ import {
QueryClientProvider,
} from "react-query";
import { ReactQueryDevtools } from "react-query/devtools";
import { persistQueryClient } from 'react-query/persistQueryClient';
import { createWebStoragePersister } from 'react-query/createWebStoragePersister'

const queryClient = new QueryClient({
defaultOptions: {
queries: {
cacheTime: 1000 * 60 * 60 * 24, // 24 hours
},
},
})

const localStoragePersister = createWebStoragePersister({storage: window.localStorage})

persistQueryClient({
queryClient,
persister: localStoragePersister,
})
const queryClient = new QueryClient();

function App() {
const [postId, setPostId] = React.useState(-1);
Expand Down Expand Up @@ -146,4 +131,4 @@ function Post({ postId, setPostId }) {
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
ReactDOM.createRoot(rootElement).render(<App />);
8 changes: 4 additions & 4 deletions examples/custom-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"eject": "rescripts eject"
},
"dependencies": {
"axios": "^0.21.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-query": "^3.5.0",
"axios": "^0.26.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-query": "^4.0.0-beta.1",
"react-scripts": "3.0.1",
"stop-runaway-react-effects": "^1.2.0",
"styled-components": "^4.3.2"
Expand Down
4 changes: 2 additions & 2 deletions examples/custom-hooks/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
import React from "react";
import ReactDOM from "react-dom";
import ReactDOM from "react-dom/client";
import { QueryClient, QueryClientProvider, useQueryClient } from "react-query";
import { ReactQueryDevtools } from "react-query/devtools";

Expand Down Expand Up @@ -102,4 +102,4 @@ function Post({ postId, setPostId }) {
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
ReactDOM.createRoot(rootElement).render(<App />);
8 changes: 4 additions & 4 deletions examples/default-query-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"eject": "rescripts eject"
},
"dependencies": {
"axios": "^0.21.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-query": "^3.5.0",
"axios": "^0.26.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-query": "^4.0.0-beta.1",
"react-scripts": "3.0.1",
"stop-runaway-react-effects": "^1.2.0",
"styled-components": "^4.3.2"
Expand Down
6 changes: 3 additions & 3 deletions examples/default-query-function/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
import React from "react";
import ReactDOM from "react-dom";
import ReactDOM from "react-dom/client";
import axios from "axios";
import {
useQuery,
Expand Down Expand Up @@ -56,7 +56,7 @@ function Posts({ setPostId }) {
const queryClient = useQueryClient();

// All you have to do now is pass a key!
const { status, data, error, isFetching } = useQuery(['/posts']);
const { status, data, error, isFetching } = useQuery(["/posts"]);

return (
<div>
Expand Down Expand Up @@ -129,4 +129,4 @@ function Post({ postId, setPostId }) {
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
ReactDOM.createRoot(rootElement).render(<App />);
2 changes: 1 addition & 1 deletion examples/focus-refetching/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"next": "9.3.2",
"react": "16.13.0",
"react-dom": "16.13.0",
"react-query": "^3.5.0"
"react-query": "^4.0.0-beta.1"
},
"scripts": {
"dev": "next",
Expand Down
2 changes: 1 addition & 1 deletion examples/load-more-infinite-scroll/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"react": "16.13.0",
"react-dom": "16.13.0",
"react-intersection-observer": "^8.33.1",
"react-query": "^3.5.0"
"react-query": "^4.0.0-beta.1"
},
"scripts": {
"dev": "next",
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"next": "latest",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-query": "^3.5.0",
"react-query": "^4.0.0-beta.1",
"resolve-from": "^5.0.0",
"web-streams-polyfill": "^3.0.3"
},
Expand Down
6 changes: 3 additions & 3 deletions examples/offline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"@tanstack/react-location": "^3.7.0",
"ky": "^0.30.0",
"msw": "^0.39.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-hot-toast": "^2.2.0",
"react-query": "^4.0.0-alpha.19",
"react-query": "^4.0.0-beta.1",
"react-scripts": "3.0.1"
},
"devDependencies": {
Expand Down
14 changes: 6 additions & 8 deletions examples/offline/src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import React from "react";
import ReactDOM from "react-dom";
import ReactDOM from "react-dom/client";
import App from "./App";
import { worker } from "./api";

worker.start();

ReactDOM.render(
<React.StrictMode>
<div style={{ padding: "16px" }}>
<App />
</div>
</React.StrictMode>,
document.getElementById("root")
const rootElement = document.getElementById("root");
ReactDOM.createRoot(rootElement).render(
<div style={{ padding: "16px" }}>
<App />
</div>
);
2 changes: 1 addition & 1 deletion examples/optimistic-updates-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"next": "9.2.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-query": "^3.5.1",
"react-query": "^4.0.0-beta.1",
"typescript": "^4.1.2"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/optimistic-updates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"next": "9.2.2",
"react": "16.13.0",
"react-dom": "16.13.0",
"react-query": "^3.5.0"
"react-query": "^4.0.0-beta.1"
},
"scripts": {
"dev": "next",
Expand Down
2 changes: 1 addition & 1 deletion examples/pagination/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"next": "9.3.2",
"react": "16.13.0",
"react-dom": "16.13.0",
"react-query": "^3.5.0"
"react-query": "^4.0.0-beta.1"
},
"scripts": {
"dev": "next",
Expand Down
6 changes: 3 additions & 3 deletions examples/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"eject": "rescripts eject"
},
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-query": "^3.5.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-query": "^4.0.0-beta.1",
"react-scripts": "3.0.1",
"stop-runaway-react-effects": "^1.2.0",
"styled-components": "^4.3.2"
Expand Down
Loading