I read this answer on returning data from async requests, but I am still having difficulty determining how to apply these answers in my application.
In the code below, I am trying to access the returned result of the getWeather async request and use that data in the jsx that follows in the return statement below getWeather.
I noticed the answers to the previous OP's question said to handle the results in a callback function, but I don't know how to get that passed back up the chain as a result of the getWeather call.
My question - how can I pass this data back and access it inside of the FiveDayWeather function?
const URL = `http://api.openweathermap.org/data/2.5/forecast?zip=94040&appid=${OPEN_WEATHER_KEY}`
const FiveDayWeather = () => {
let days = getWeather()
return(
<div className="five-day-weather">
<div className="day-of-week-item">
<div className="day">Hi Again</div>
<div className="image-indicator"></div>
<div className="temp"></div>
</div>
</div>
)
}
function getWeather() {
axios.get(URL)
.then(function(response) {
handleData(response)
})
}
function handleData(response) {
return response
}