Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

105
Vistas
Promise all with axios in react native app

I'm making a react-native weather forecast app. And I'm trying to get all the data using 2 promise all methods

This is the function I call in useEffect

async function getData(){
  try{

    Promise.all(_.map(savedPlaces, getCurrentWeather)).then((response) => {console.log("current", response.data)})
    Promise.all(_.map(savedPlaces, getDailyWeather)).then((response) => {console.log("daily", response.data)})

  }
  catch(error){
    console.log(error)
  }
}

The savedPlaces variable is an array with names of the cities I want to get the weather for

And this is one of the two fuctions i use to get the data

const getCurrentWeather = async (places) =>{

  const options = {
    method: 'GET',
    url: 'https://community-open-weather-map.p.rapidapi.com/weather',
    params: {q: places.name, lang: 'null', units: 'metric', mode: JSON},
    headers: {
      'x-rapidapi-host': 'community-open-weather-map.p.rapidapi.com',
      'x-rapidapi-key': 'xxx'
    }
  };

  const request = await axios.request(options).then(response => {console.log(response.data)})

  return request

}

The other funtion is basicaly the same except little changes in options

And the issu is that I can see the data in print out in this code fragment

.then(response => {console.log(response.data)})

inside the getCurrentWeather functions but when I try to print them out in .then after Promise.all I get undefined, same with the other function.

current [undefined, undefined]

And I'm asking how to properly do it

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Here:

const request = await axios.request(options)
    .then(response => {console.log(response.data)})

The callback under then prints the data in the console, but has no return statement (returns undefined). Therefore this

return request

returns undefined wrapped in a promise.

Add return response (or return response.data) after the console.log and it should get better.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda