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

92
Vistas
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 Respuestas
Responde la pregunta

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 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