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

84
Views
react firebase firestore Expected type 'Pa', but it was: a custom Va object

I am trying to receive the data from an uploaded file from firebase firestore and save it in an array

but its throws me an "Uncaught (in promise) FirebaseError: Expected type 'Pa', but it was: a custom Va object"

Thanks for help

import { useState, useEffect } from "react";
import { projectFirestore } from "../firebase/config";
import { collection as col, onSnapshot, query, orderBy } from "firebase/firestore";


const useFirestore = (collection) => {

    const [docs, setDocs] = useState([]);

    useEffect (() => {
        //new collection reference
        const newcoll = (col(projectFirestore, collection))
            const q = query(newcoll, orderBy('createdAt', 'desc'));
            const unsub = onSnapshot(q, (snapshot) => {
                let documents = [];
                snapshot.forEach(doc => {
                    documents.push({...doc.data(), id: doc.id})
                })
                setDocs(documents);
            });

        return () => newcoll();
    },[collection]);

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I would make a few changes in the code to be:

 useEffect (() => {
   if(collection) { 
     const newcoll = col(projectFirestore, collection);
     const q = query(newcoll, orderBy('createdAt', 'desc'));
     const unsub = onSnapshot(q, (snapshot) => {
       let documents = [];
       snapshot.forEach(doc => {
          documents.push({...doc.data(), id: doc.id})
       })
       setDocs(documents);
     });

     return unsub;
  }
},[collection]);

Changes include:

  • returning unsub instead of () => newcoll()
  • checking that collection has a truthy value
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!