-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,35 @@ | ||
import './App.css'; | ||
// Weather.js | ||
|
||
import React, { useEffect, useState } from "react"; | ||
import WeatherCard from "./WeatherCard"; | ||
|
||
function Weather() { | ||
const Weather = () => { | ||
const [weatherData, setWeatherData] = useState(null); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
try { | ||
const response = await fetch('http://wttr.in/?format=%C+%t+%w'); | ||
const result = await response.text(); | ||
const response = await fetch('http://wttr.in/?format=j1'); | ||
const result = await response.json(); | ||
|
||
console.log("Weather Data:", result); | ||
|
||
setWeatherData(result); | ||
} catch (error) { | ||
console.error("Error fetching weather data:", error); | ||
} | ||
}; | ||
|
||
fetchData(); | ||
}, []); // Empty dependency array ensures the effect runs only once when the component mounts | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<h2>Weather Page</h2> | ||
{weatherData && <WeatherCard weatherData={weatherData} />} | ||
<WeatherCard weatherData={weatherData} /> | ||
{/* Render other components or data as needed */} | ||
</div> | ||
); | ||
} | ||
}; | ||
|
||
export default Weather; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters