Files
go-weather/frontend/src/hooks/weather-history.tsx
T
cody 35b0c2396f add the very basics of a plot
Also troubleshoot to fix vite config for deduplicating react and
react-dom
2026-02-18 19:52:08 -08:00

30 lines
819 B
TypeScript

import { useQuery } from '@tanstack/react-query'
// {"id":1001,"city":"Salem","temp":66.7,"feels_like":67.17,"humidity":87,"conditions":"scattered clouds","fetched_at":"2026-02-18T22:16:38.067097Z"}
interface WeatherHistory {
id: number;
city: string;
temp: number;
feels_like: number;
humidity: number;
conditions: string;
fetched_at: string;
}
async function fetchWeatherHistory(): Promise<WeatherHistory[]>{
const res = await fetch("/api/weather/history");
if(!res.ok) throw new Error("Failed to fetch weather history");
return res.json();
}
function WeatherHistory() {
const {data, isLoading, error} = useQuery({
queryKey: ["weather-history"],
queryFn: fetchWeatherHistory,
});
return {data, isLoading, error}
}
export default WeatherHistory