local-weather/components/WeatherNow.tsx
ChrQR 7b97a0eb65 Fixed some things.
Need to fix google places call. It is refreshing the page when receiving the data, thus resetting the state.

It's a job for tomorrow.
2024-05-06 23:22:57 +02:00

31 lines
801 B
TypeScript

"use client";
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";
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]);
return (
<>
<h1>Forecast</h1>
<Temperature tempInfo={weather?.main} />
<p></p>
</>
);
}