fix: use IMGW Hybrid for current weather
This commit is contained in:
18
hooks/use-current-weather.ts
Normal file
18
hooks/use-current-weather.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
"use client";
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { fetchImgwCurrentWeather } from "@/lib/imgw-current-api";
|
||||
import { QUERY_GC_TIME } from "@/lib/constants";
|
||||
|
||||
const CURRENT_WEATHER_STALE_TIME = 2 * 60 * 1000;
|
||||
|
||||
export function useCurrentWeather(latitude?: number, longitude?: number) {
|
||||
return useQuery({
|
||||
queryKey: ["imgw-current-weather", latitude, longitude],
|
||||
queryFn: ({ signal }) => fetchImgwCurrentWeather(latitude as number, longitude as number, signal),
|
||||
staleTime: CURRENT_WEATHER_STALE_TIME,
|
||||
gcTime: QUERY_GC_TIME,
|
||||
retry: 1,
|
||||
enabled: Number.isFinite(latitude) && Number.isFinite(longitude),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user