import useSWR from "swr"; import { BiError } from "react-icons/bi"; import { useTranslation } from "react-i18next"; import Icon from "./icon"; export default function WeatherApi({ options }) { const { t, i18n } = useTranslation(); const { data, error } = useSWR( `/api/widgets/weather?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}` ); if (error) { return (
API Error
); } if (!data) { return
; } if (data.error) { return
; } const unit = options.units === "metric" ? "celsius" : "fahrenheit"; return (
{options.label && `${options.label}, `} {t("common.number", { value: options.units === "metric" ? data.current.temp_c : data.current.temp_f, style: "unit", unit, })} {data.current.condition.text}
); }