"use client"; import { getHourlyForecast } from "@/app/actions"; import Temperature from "./Temperature"; import { Forecast, WeatherContextType } from "@/types/types"; import { createContext, useContext, useEffect, useState } from "react"; import { defaultHourlyForecast } from "@/app/defaultState"; import { LocationContext } from "@/context/LocationContext"; import WeatherHero from "./WeatherHero"; import DailyCard from "./DailyCard/DailyCard"; export const WeatherContext = createContext({ weather: defaultHourlyForecast, setWeather: () => {}, // Default function, does nothing }); export default function WeatherNow() { const { geoLocation } = useContext(LocationContext); const [weather, setWeather] = useState(defaultHourlyForecast); const contextValue: WeatherContextType = { weather, setWeather, }; useEffect(() => { let mounted = true; getHourlyForecast(geoLocation).then((data) => { if (mounted) { setWeather(data); } }); return () => { mounted = false; }; }, [geoLocation]); return (

Here is the weather today in {geoLocation.name}

And the forecast for the coming week

{weather.daily && weather.daily.apparent_temperature_max.map((temp, index) => ( index > 0 && index < 7 && // Ensure we only render the next 6 days ))}
); }