Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!