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

159
Vistas
What does setDoc function return?

I'm using firebase in my reactjs+typescript project. I want to write a document in firebase and I'm using setDoc to do this job.

import { doc, setDoc } from 'firebase/firestore';

setDoc(doc(database, `path`), objData)

When you check the function return it says Promise<...>. But, how am I supposed to use then() catch() promise handlers if I don't know what the promise returns when it fullfil/reject?

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

0

I'm not very familiar with Firebase but after looking around it seems the return is just going to be whether or not the setDoc() was successful. So the .then() would mean yes and the .catch() would mean no. So really all you would want is something like this

import { doc, setDoc } from 'firebase/firestore';

setDoc(doc(database, `path`), objData)
.then(() => {
console.log("Successful")})
.catch((error) => {
console.log(`Unsuccessful returned error ${error}`)});

Again I am not fully sure about the exact values returned as I could not find much but if there is a result value given you would place it in the .then((result) => {console.log(result)}).

about 4 years ago · Juan Pablo Isaza Denunciar

0

The firebase documentation suggest using await, so here you have a complete example of error handling with await and cleanup with finally.

import { doc, setDoc } from 'firebase/firestore';


async function run() {
    try {
        await setDoc(doc(database, `path`), objData)
    } catch (e) {
        console.error(e); // handle your error here
    } finally {
        console.log('Cleanup here'); // cleanup, always executed
    }
}

run();
about 4 years ago · Juan Pablo Isaza Denunciar

0

In Typescript, you don't need to specify the promise return type precisely. Here's an example of how to use promise handlers with setDoc:

import { doc, setDoc } from 'firebase/firestore';

setDoc(doc(database, `path`), objData)
  .then((data) => {console.log('data', data);})
  .catch((err) => {console.log('err', err);})
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