Files
wtr/hooks/use-weather-stations.ts

27 lines
711 B
TypeScript

"use client";
import { useQuery } from "@tanstack/react-query";
import { fetchSynopStation, fetchSynopStations } from "@/lib/imgw-api";
import { QUERY_GC_TIME, QUERY_STALE_TIME } from "@/lib/constants";
export function useWeatherStations() {
return useQuery({
queryKey: ["synop-stations"],
queryFn: ({ signal }) => fetchSynopStations(signal),
staleTime: QUERY_STALE_TIME,
gcTime: QUERY_GC_TIME,
retry: 2,
});
}
export function useWeatherStation(id: string) {
return useQuery({
queryKey: ["synop-station", id],
queryFn: ({ signal }) => fetchSynopStation(id, signal),
staleTime: QUERY_STALE_TIME,
gcTime: QUERY_GC_TIME,
retry: 2,
enabled: Boolean(id),
});
}