mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
**feat:** adds a component to display API endpoints and anon keys in docs if user is authenticated makes the getting started UX smoother so users don't have to jump back and forth between docs and trying to find their keys in dashboard **out of scope:** it would be very cool to display these directly in the code blocks. I looked into it and it would require quite a bit of work forking and modifying code-hike, so out of scope for now Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
TypeScript
import { QueryClient } from '@tanstack/react-query'
|
|
import { useState } from 'react'
|
|
|
|
let queryClient: QueryClient | undefined
|
|
|
|
function getQueryClient() {
|
|
const _queryClient =
|
|
queryClient ??
|
|
new QueryClient({
|
|
defaultOptions: {
|
|
queries: {
|
|
retry: (failureCount, error) => {
|
|
// Don't retry on 404s
|
|
if (
|
|
typeof error === 'object' &&
|
|
error !== null &&
|
|
'code' in error &&
|
|
error.code === 404
|
|
) {
|
|
return false
|
|
}
|
|
|
|
if (failureCount < 3) {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
// For SSG and SSR always create a new queryClient
|
|
if (typeof window === 'undefined') return _queryClient
|
|
|
|
// Create the query client once in the client
|
|
if (!queryClient) queryClient = _queryClient
|
|
return queryClient
|
|
}
|
|
|
|
export function useRootQueryClient() {
|
|
const [_queryClient] = useState(() => getQueryClient())
|
|
|
|
return _queryClient
|
|
}
|