Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda