Added weather data component to display weather data - also added function to display data
This commit is contained in:
@@ -4,7 +4,9 @@ export const fetchWeather = async (city: string, apiKey: string) => {
|
||||
`http://api.openweathermap.org/geo/1.0/direct?q=${city}&appid=${apiKey}`
|
||||
).then((response) => {
|
||||
if (response.status === 401) {
|
||||
console.error("You are not authorized to access this resource. Please check your API key.");
|
||||
console.error(
|
||||
"You are not authorized to access this resource. Please check your API key."
|
||||
);
|
||||
} else if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
@@ -18,5 +20,5 @@ export const fetchWeather = async (city: string, apiKey: string) => {
|
||||
const weather = await fetch(
|
||||
`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${apiKey}`
|
||||
).then((response) => response.json());
|
||||
console.log(weather);
|
||||
localStorage.setItem("weather", JSON.stringify(weather));
|
||||
};
|
||||
|
Reference in New Issue
Block a user