0

I make an api call , check the data to make sure it's there but for some reason my array that it return is empty.

export const fetchFiveDayWeather = (lat, lon) => {
  axios.get(
      `http://api.openweathermap.org/data/2.5/weather? 
 lat=${lat}&lon=${lon}&APPID=${apiKey}&units=metric`
    )
    .then((response) => {
      console.log(response.data)
      return response.data
    });
}

Code of the function:

shrys
  • 5,860
  • 2
  • 21
  • 36

1 Answers1

0

You have to call the fetchFiveDayWeather with then like below. Because the then returns a promise and it's an async call.

fetchFiveDayWeather().then( response => {
   console.log(response );
})
Sohail Ashraf
  • 10,078
  • 2
  • 26
  • 42