Create get query client to work on next
This commit is contained in:
parent
1197f51518
commit
70d3434e5b
1 changed files with 37 additions and 0 deletions
37
frontend/src/app/api/get-query-client.ts
Normal file
37
frontend/src/app/api/get-query-client.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue