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

95
Vistas
Not receiving the correct data from Promises?

I have a function that fetches data from an API, and the function works correctly as intended:

 const getStockData = async (stock) => {
try {
  const response = await axios.get(`${BASE_URL}${stock}${KEY_URL}`);
  console.log(response);
  return response;
} catch (error) {
  console.error('Error', error.message);
}

};

And I have another function that gets data from my firebase which then passes in the .ticker into the function above however when I log the response from the promise the data is returned null Is there a reason why its not working as intended?

const getMyStocks = async () => {
let promises = [];
let tempData = [];
const querySnapshot = await getDocs(collection(db, 'myStocks'));
querySnapshot.forEach((doc) => {
  console.log(doc.data().ticker);
  promises.push(
    getStockData(doc.data().ticker).then((res) => {
      console.log(res);
      tempData = {
        id: doc.id,
        data: doc.data(),
        info: res.data,
      };
    })
  );
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

getMyStocks must return the resolution of the promises it creates...

// to reduce nested promises, this takes an FB doc and adds the getStockData query to it
const getFBAndTickerData = async doc => {
  return getStockData(doc.data().ticker).then(res => {
    console.log(res);
    return {
      id: doc.id,
      data: doc.data(),
      info: res.data,
    };
  });
}

const getMyStocks = async () => {
  const querySnapshot = await getDocs(collection(db, 'myStocks'));
  let promises = querySnapshot.docs.map(doc => {
    console.log(doc.data().ticker);
    return getFBAndTickerData(doc);
  });
  return Promise.all(promises);
}
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