mirror of https://github.com/langgenius/dify.git
30 lines
878 B
TypeScript
30 lines
878 B
TypeScript
'use client'
|
|
|
|
import type { QueryClient } from '@tanstack/react-query'
|
|
import type { FC, PropsWithChildren } from 'react'
|
|
import { QueryClientProvider } from '@tanstack/react-query'
|
|
import { useState } from 'react'
|
|
import { TanStackDevtoolsLoader } from '@/app/components/devtools/tanstack/loader'
|
|
import { makeQueryClient } from './query-client-server'
|
|
|
|
let browserQueryClient: QueryClient | undefined
|
|
|
|
function getQueryClient() {
|
|
if (typeof window === 'undefined') {
|
|
return makeQueryClient()
|
|
}
|
|
if (!browserQueryClient)
|
|
browserQueryClient = makeQueryClient()
|
|
return browserQueryClient
|
|
}
|
|
|
|
export const TanstackQueryInitializer: FC<PropsWithChildren> = ({ children }) => {
|
|
const [queryClient] = useState(getQueryClient)
|
|
return (
|
|
<QueryClientProvider client={queryClient}>
|
|
{children}
|
|
<TanStackDevtoolsLoader />
|
|
</QueryClientProvider>
|
|
)
|
|
}
|