App Container updated with state, API and form
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
import React,{useState} from 'react'; | |
import './App.css'; | |
import Form from './Form'; | |
import Weather from './Weather'; | |
function App() { | |
const [weather,setWeather] = useState([]) | |
const APIKEY = 'INSERT YOUR OWN KEY HERE' | |
async function fetchData(e) { | |
e.preventDefault() | |
const apiData = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=London,uk&APPID=${APIKEY}`) | |
.then( res => res.json()) | |
.then(data => data) | |
setWeather({ | |
data: apiData | |
} | |
) | |
} | |
return ( | |
<div className="App"> | |
<h3>WEATHER APP</h3> | |
<Form getWeather={fetchData} /> | |
{console.log(weather.data)} | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment