Download react-query/examples/react/nextjs-app-prefetching/app/get-query-client.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/react/nextjs-app-prefetching/app/get-query-client.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/react/nextjs-app-prefetching/app/get-query-client.ts
-
curl -L -o get-query-client.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/react/nextjs-app-prefetching/app/get-query-client.ts
1.05 kB
| import { | |
| QueryClient, | |
| defaultShouldDehydrateQuery, | |
| isServer, | |
| } from '@tanstack/react-query' | |
| function makeQueryClient() { | |
| return new QueryClient({ | |
| defaultOptions: { | |
| queries: { | |
| staleTime: 60 * 1000, | |
| }, | |
| dehydrate: { | |
| // include pending queries in dehydration | |
| shouldDehydrateQuery: (query) => | |
| defaultShouldDehydrateQuery(query) || | |
| query.state.status === 'pending', | |
| }, | |
| }, | |
| }) | |
| } | |
| let browserQueryClient: QueryClient | undefined = undefined | |
| export function getQueryClient() { | |
| if (isServer) { | |
| // Server: always make a new query client | |
| return makeQueryClient() | |
| } else { | |
| // Browser: make a new query client if we don't already have one | |
| // This is very important, so we don't re-make a new client if React | |
| // suspends during the initial render. This may not be needed if we | |
| // have a suspense boundary BELOW the creation of the query client | |
| if (!browserQueryClient) browserQueryClient = makeQueryClient() | |
| return browserQueryClient | |
| } | |
| } | |