import useSWR from "swr"; import { BiError } from "react-icons/bi"; import Icon from "./icon"; export default function OpenWeatherMap({ options }) { const { data, error } = useSWR(`/api/widgets/openweathermap?${new URLSearchParams(options).toString()}`); if (error || data?.cod === 401) { return (
API Error
); } if (!data) { return
; } if (data.error) { return
; } return (
data.sys.sunrise && data.dt < data.sys.sundown ? "day" : "night"} />
{options.label && `${options.label}, `} {data.main.temp.toFixed(1)}° {data.weather[0].description.charAt(0).toUpperCase() + data.weather[0].description.slice(1)}
); }