Problem with onSnapshot Firebase - Uncaught FirebaseError: Expected type 'Ea', but it was: a custom pn object

Viewed 24

I am trying to use onSnapshot to get data from firebase but I am getting an error. Everything is working when I am using getDocs(), but with onSnapshot() there is a problem. Does anyone know what might be a problem?

Firebase config

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

const firebaseApp = initializeApp({
// hidden configuration
});
const db = getFirestore(firebaseApp)
export default db;

React code

const [todos, setTodos] = useState < DocumentData[] > ();

useEffect(() => {
  const unsubscribe = onSnapshot(collection(db, "todos"), (snapshot) => {
    setTodos(
      snapshot.docs.map((doc) => ({
        data: doc.data(),
        id: doc.id,
      }))
    );
  });
  return () => {
    unsubscribe();
  };
}, []);

Error

FirebaseError: Expected type 'Ea', but it was: a custom pn object

0 Answers
Related