add tanstack/react-query
This commit is contained in:
@@ -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__
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user