mono/packages/ui/src/hooks/useSystemInfo.ts
2026-02-17 20:18:27 +01:00

25 lines
688 B
TypeScript

import { useQuery } from '@tanstack/react-query';
interface SystemInfo {
env: Record<string, string>;
}
export const useSystemInfo = () => {
return useQuery<SystemInfo>({
queryKey: ['system-info'],
queryFn: async () => {
const res = await fetch('/api/system-info');
if (!res.ok) throw new Error('Failed to fetch system info');
return res.json();
},
staleTime: Infinity,
gcTime: Infinity,
});
};
/** Shorthand: get a specific env variable */
export const useEnvVar = (key: string): string | undefined => {
const { data } = useSystemInfo();
return data?.env[key];
};