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

704
Vistas
Uncaught TypeError: _firebase_js__WEBPACK_IMPORTED_MODULE_3__.db.collection is not a function

I think I know why this isn't working (the way Firebase had its syntax changed in v9 or something?), but I'm not sure what changes. I've checked the documentation, but I'm still confused.

import { db } from './firebase.js';  

function App() {
  const [posts, setPosts] = useState([

  ]);

  useEffect(() => {
    db.collection('posts').onSnapshot(snapshot => {
      setPosts(snapshot.docs.map(doc => doc.data()));
    });
  }, []);

The error I get is this: Uncaught TypeError: firebase_js__WEBPACK_IMPORTED_MODULE_3_.db.collection is not a function or something similar to this except for my .map().

This is my guess of what I should write:

useEffect(() => {
    const q = query(collection(db, "posts"))
    setPosts(onSnapshot(q, (querySnapshot) => {
      console.log("Data", querySnapshot.docs.map(d => doc.data()))
    }))
  }, []);

But I can't seem to get this to work either.

firebase.js in case its needed:

import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";

const firebaseConfig = {
  ...
};

const app = initializeApp(firebaseConfig);

const db = getFirestore(app);

export { db };

(edit) Solution:

useEffect(() => {
    const q = query(collection(db, "posts"))
    onSnapshot(q, (querySnapshot) => {
      console.log("Data", querySnapshot.docs.map(d => d.data()))
    })
  }, []);
about 4 years ago · Santiago Gelvez
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