fixed weather code context
This commit is contained in:
parent
30518a0fba
commit
0a0481d63f
@ -26,7 +26,6 @@ export default function Home() {
|
|||||||
<div className='block mx-auto max-w-4xl'>
|
<div className='block mx-auto max-w-4xl'>
|
||||||
<LocationContext.Provider value={contextValue}>
|
<LocationContext.Provider value={contextValue}>
|
||||||
<LocationSearch />
|
<LocationSearch />
|
||||||
<WeatherIcon />
|
|
||||||
<WeatherNow />
|
<WeatherNow />
|
||||||
</LocationContext.Provider>
|
</LocationContext.Provider>
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,4 +10,3 @@ export default function Temperature() {
|
|||||||
<p>{feels}°C</p>
|
<p>{feels}°C</p>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ import sun from '../public/sun.svg'
|
|||||||
|
|
||||||
import { useContext } from "react";
|
import { useContext } from "react";
|
||||||
import { WeatherContext } from "./WeatherNow";
|
import { WeatherContext } from "./WeatherNow";
|
||||||
import { HourlyForecast } from "@/types/types";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -83,11 +82,10 @@ function getCurrentWeatherIcon(weatherCode: number) {
|
|||||||
|
|
||||||
export default function WeatherIcon() {
|
export default function WeatherIcon() {
|
||||||
const { weather } = useContext(WeatherContext)
|
const { weather } = useContext(WeatherContext)
|
||||||
const weatherCode = weather.current.weather_code
|
|
||||||
return(
|
return(
|
||||||
<>
|
<>
|
||||||
<Image src={getCurrentWeatherIcon(weatherCode)} alt="Weather icon"/>
|
<Image src={getCurrentWeatherIcon(weather.current.weather_code)} alt="Weather icon"/>
|
||||||
{console.log(weatherCode)}
|
{JSON.stringify(weather.current.weather_code)}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
};
|
};
|
@ -6,6 +6,7 @@ import { HourlyForecast, WeatherContextType} from "@/types/types";
|
|||||||
import { createContext, useContext, useEffect, useState } from "react";
|
import { createContext, useContext, useEffect, useState } from "react";
|
||||||
import { defaultHourlyForecast } from "@/app/defaultState";
|
import { defaultHourlyForecast } from "@/app/defaultState";
|
||||||
import { LocationContext } from "@/app/page";
|
import { LocationContext } from "@/app/page";
|
||||||
|
import WeatherIcon from "./WeatherIcon";
|
||||||
|
|
||||||
export const WeatherContext = createContext<WeatherContextType>({
|
export const WeatherContext = createContext<WeatherContextType>({
|
||||||
weather: defaultHourlyForecast,
|
weather: defaultHourlyForecast,
|
||||||
@ -35,6 +36,7 @@ export default function WeatherNow() {
|
|||||||
<>
|
<>
|
||||||
<h1>Here is the current weather in {geoLocation.name}</h1>
|
<h1>Here is the current weather in {geoLocation.name}</h1>
|
||||||
<WeatherContext.Provider value={contextValue}>
|
<WeatherContext.Provider value={contextValue}>
|
||||||
|
<WeatherIcon />
|
||||||
<Temperature />
|
<Temperature />
|
||||||
</WeatherContext.Provider>
|
</WeatherContext.Provider>
|
||||||
</>
|
</>
|
||||||
|
Loading…
Reference in New Issue
Block a user