local-weather/components/WeatherNow.tsx

31 lines
801 B
TypeScript
Raw Normal View History

"use client";
2024-05-04 21:04:30 +00:00
import { getForecast } from "@/app/actions";
import Temperature from "./Temperature";
import { Forecast, coordType } from "@/types/types";
import { useEffect, useState } from "react";
import { defaultForecast } from "@/app/defaultState";
2024-05-04 21:04:30 +00:00
export default function WeatherNow(props: { geoLocation: coordType }) {
// const weather = getForecast(props.geoLocation);
const [weather, setWeather] = useState<Forecast>(defaultForecast);
useEffect(() => {
let mounted = true;
getForecast(props.geoLocation).then((data) => {
if (mounted) {
setWeather(data);
}
});
return () => {
mounted = false;
};
}, [props.geoLocation]);
2024-05-04 21:04:30 +00:00
return (
<>
2024-05-04 21:04:30 +00:00
<h1>Forecast</h1>
<Temperature tempInfo={weather?.main} />
2024-05-04 21:04:30 +00:00
<p></p>
</>
2024-05-04 21:04:30 +00:00
);
}