How to convert this Firebase v8 code to v9 code

Viewed 16

i am new to firebase v9 can anybody help me convert this code to import data from firebase collection-firebase Collection Import

1 Answers

As per @Dharmaraj says on the link that he provides you may check this sample code below for v9. You may refer to this documentation.

import database from './firebase';
import { doc, onSnapshot, collection, query, where, onSnapshot } from "firebase/firestore";

    const [posts,setPosts] = useStat([]);

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