Files
LaunchPad/apps/frontend/src/hooks/useDevices.ts

22 lines
534 B
TypeScript

import { useQuery } from "@tanstack/react-query";
import type { Device, Service } from "@launchpad/shared";
export interface DeviceWithServices extends Device {
services: Service[];
}
async function fetchDevices(): Promise<DeviceWithServices[]> {
const res = await fetch("/api/devices");
if (!res.ok) {
throw new Error(`Geräte konnten nicht geladen werden (HTTP ${res.status})`);
}
return res.json();
}
export function useDevices() {
return useQuery({
queryKey: ["devices"],
queryFn: fetchDevices,
});
}