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

104
Visualizações
Firebase resolve Promise

I'm starting in the world of promises and there is one thing I can't understand.

I am trying to make a system that returns a document from a Firebase collection by its ID.

For this I use 2 functions

 const getProductDataById = async(idProduct)=> {
    
        const docSnap = await getDoc(doc(db, "products", idProduct));
        if (docSnap.exists()) {
            return docSnap.data();       
        } 
        else {  
            console.log("No such document!"); 
        }
    }


    const getProduct = (idProduct)=>{
        
        let ProductDataPromise = getProductDataById (idProduct);
        
        //I don't know how resolve Promise

        return ProductData;
       
        
    }

The problem is that I don't know in the second how to resolve the Promise so that this function returns the desired object.

Thanks!!

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

You should be able to just await the call to the first function:

const getProduct = async (idProduct)=>{
  let ProductData = await getProductDataById(idProduct);
  // Do something with ProductData?
  return ProductData;      
}

Of course, if you're not doing anything with ProductData, then this is equivalent to just calling getProductDataById directly.

about 4 years ago · Santiago Gelvez Relatório
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