location getting passed as prop now
This commit is contained in:
		
							parent
							
								
									910e61e51c
								
							
						
					
					
						commit
						c33c7568d1
					
				@ -54,23 +54,27 @@ interface LocationType {
 | 
				
			|||||||
  latitude: string;
 | 
					  latitude: string;
 | 
				
			||||||
  longtitude: string;
 | 
					  longtitude: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					const kelvin = 273.15;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getForecast(location: LocationType): Promise<Forecast> {
 | 
					async function getForecast(location: LocationType): Promise<Forecast> {
 | 
				
			||||||
  const {latitude, longtitude} = location;
 | 
					  const {latitude, longtitude} = location;
 | 
				
			||||||
  const appId = '546911d860cb81f16585f7973b394b70';
 | 
					  const appId = '546911d860cb81f16585f7973b394b70';
 | 
				
			||||||
  const res = await fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longtitude}&appid=${appId}`)
 | 
					  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}`);
 | 
					    throw new Error(`This is not great ${error}`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  return res.json();
 | 
					  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 weather = await getForecast(location)
 | 
				
			||||||
 | 
					    const temp = weather.main.temp - kelvin
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
      <main>
 | 
					      <main>
 | 
				
			||||||
        <h1>Forecast</h1>
 | 
					        <h1>Forecast</h1>
 | 
				
			||||||
        <p>{weather.name}</p>
 | 
					        <p>{temp}</p>
 | 
				
			||||||
 | 
					        <p></p>
 | 
				
			||||||
      </main>
 | 
					      </main>
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user