add tanstack/react-query

This commit is contained in:
smanylov
2025-12-02 17:11:53 +07:00
parent d89cc35fca
commit 6d47fa7fbb
15 changed files with 209 additions and 94 deletions
+31
View File
@@ -0,0 +1,31 @@
import { QueryClient } from '@tanstack/react-query'
import { cache } from 'react'
const getQueryClientDefaultConfig = () => ({
defaultOptions: {
queries: {
staleTime: 60 * 1000,
refetchOnWindowFocus: false,
retry: 1,
},
},
})
export function makeQueryClient() {
return new QueryClient(getQueryClientDefaultConfig())
}
export const getQueryClient = cache(() => {
if (typeof window === 'undefined') {
return new QueryClient(getQueryClientDefaultConfig())
} else {
// @ts-ignore
if (!globalThis.__APP_QUERY_CLIENT__) {
// @ts-ignore
globalThis.__APP_QUERY_CLIENT__ = makeQueryClient()
}
// @ts-ignore
return globalThis.__APP_QUERY_CLIENT__
}
})