Files
superlist/apps/web/src/hooks/use-health.ts

27 lines
603 B
TypeScript

import { queryOptions, useQuery } from '@tanstack/react-query'
import { apiFetch } from '@/lib/api-client'
export type HealthStatus = {
status: 'ok'
uptimeSeconds: number
timestamp: string
}
/**
* Query options are exported so route loaders can prefetch the same data:
*
* ```ts
* loader: ({ context }) => context.queryClient.ensureQueryData(healthQueryOptions())
* ```
*/
export const healthQueryOptions = () =>
queryOptions({
queryKey: ['health'],
queryFn: () => apiFetch<HealthStatus>('/health'),
})
export function useHealth() {
return useQuery(healthQueryOptions())
}