mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 03:55:38 -04:00
Replace manual fetch/useState/useEffect patterns with SWR hooks in system health section and command palette search, gaining automatic caching, request deduplication, and stale-while-revalidate. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
20 lines
492 B
TypeScript
20 lines
492 B
TypeScript
import useSWR from "swr";
|
|
import type { SystemHealthData } from "@/lib/services/system-health";
|
|
import { fetcher } from "@/lib/swr/fetcher";
|
|
|
|
export function useSystemHealth() {
|
|
const { data, error, isLoading, isValidating, mutate } =
|
|
useSWR<SystemHealthData>("/api/admin/system-health", fetcher, {
|
|
revalidateOnFocus: true,
|
|
dedupingInterval: 10_000,
|
|
});
|
|
|
|
return {
|
|
data: data ?? null,
|
|
error,
|
|
isLoading,
|
|
isValidating,
|
|
refresh: () => mutate(),
|
|
};
|
|
}
|