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
how can a function return data after the promise is resolved in javascript?

I am creating a react native project where on the click of a button I want some data to be fetched from firebase and printed in the console..But instead I am getting undefined printed..what am i doing incorrectly? this is the function being called after the button is clicked:

  function printTodos() {
    console.log(loadFutureTodos()); //this is where I am getting undefined..but why? 
  }

this is the function which fetches data from firebase:

  function loadFutureTodos() {
    let allFutureTodos = [];
    firestore()
      .collection('todos')
      .where('user', '==', auth().currentUser.uid)
      .where('time', '==', futureTime)
      .orderBy('priority', 'desc')
      .get()
      .then(snap => {
        snap.docs.map(each => {
          let eachdict = {
            id: each.id,
            taskName: each.get('taskName'),
            taskDesc: each.get('taskDesc'),
          };
          allFutureTodos.push(eachdict);
        });
     console.log(allFutureTodos);//this works perfectly..all the todos in firebase get fetched
      })
      .finally(() => {
        return allFutureTodos;
      });
  }
about 4 years ago · Juan Pablo Isaza
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