mirror of
https://github.com/privacy-scaling-explorations/pse.dev.git
synced 2026-01-15 00:58:19 -05:00
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
"use client"
|
|
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
|
|
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"
|
|
|
|
// Create QueryClient function to avoid issues with React StrictMode
|
|
function makeQueryClient() {
|
|
return new QueryClient({
|
|
defaultOptions: {
|
|
queries: {
|
|
staleTime: 5 * 60 * 1000, // 5 minutes
|
|
gcTime: 10 * 60 * 1000, // 10 minutes (previously cacheTime)
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
let browserQueryClient: QueryClient | undefined = undefined
|
|
|
|
function getQueryClient() {
|
|
if (typeof window === "undefined") {
|
|
return makeQueryClient()
|
|
} else {
|
|
if (!browserQueryClient) browserQueryClient = makeQueryClient()
|
|
return browserQueryClient
|
|
}
|
|
}
|
|
|
|
export const QueryClientProviderLayout = ({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode
|
|
}) => {
|
|
const queryClient = getQueryClient()
|
|
const withQueryDevtools = false
|
|
|
|
return (
|
|
<QueryClientProvider client={queryClient}>
|
|
{children}
|
|
{withQueryDevtools && <ReactQueryDevtools initialIsOpen={false} />}
|
|
</QueryClientProvider>
|
|
)
|
|
}
|