diff --git a/components/Weather.tsx b/components/Weather.tsx index fa80dc3..e4f8cf4 100644 --- a/components/Weather.tsx +++ b/components/Weather.tsx @@ -54,23 +54,27 @@ interface LocationType { latitude: string; longtitude: string; } +const kelvin = 273.15; async function getForecast(location: LocationType): Promise { const {latitude, longtitude} = location; const appId = '546911d860cb81f16585f7973b394b70'; const res = await fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longtitude}&appid=${appId}`) - if (!res.ok){ + if (!res.ok) { throw new Error(`This is not great ${error}`); } return res.json(); - } +} -export default async function Weather(location: LocationType) { +export default async function Weather(props: {location: LocationType}) { + const location = props.location const weather = await getForecast(location) + const temp = weather.main.temp - kelvin return (

Forecast

-

{weather.name}

+

{temp}

+

); } \ No newline at end of file