I've got a function getData() that grabs a JSON object of the current weather conditions. While I can see the JSON object in the console, I can't seem to pass it to a usable variable. What am I missing here?
const getData = () => {
let url = `https://api.openweathermap.org/data/2.5/weather?q=Asheville&appid=${key}`
fetch(url)
.then((response) => {
return response.json();
})
.then((response) => {
console.log(response);
})
.catch((err) => {
console.log(err);
})
}
function App() {
let data = getData();
console.log(data);
return (
<div className="App">
<Forecast />
</div>
);
}
I've tried it a couple ways and can't get it to work. Also for some reason it logs in the console twice and I'm not sure why. Any advice is greatly appreciated!