i was following along the guidelines that firebase provides and i ran into this error.
const [orders, setOrders] = useState([]);
useEffect(() => {
const getData = async () => {
if (user) {
const collRef = getDocs(db, "users", user?.id);
const orderedRef = query(collRef, orderBy("created", "desc"));
const docSnap = await onSnapshot(orderedRef);
setOrders(docSnap);
orders.map((doc) => ({
id: doc.id,
data: doc.data(),
}));
} else {
setOrders([]);
}
};
getData();
}, [user]);
and i get this
Orders.jsx:36 Uncaught (in promise) FirebaseError: Expected type 'Ea', but it was: a custom Na object
--UPDATE--
I just wanted to point out that I'm new to firebase and I was following a video guide that is from a couple years ago and they weren't using the v9 modular style.
From their video their code goes as follows:
useEffect(() => {
if(user) {
db
.collection('users')
.doc(user?.uid)
.collection('orders')
.orderBy('created', 'desc')
.onSnapshot(snapshot => (
setOrders(snapshot.docs.map(doc => ({
id: doc.id,
data: doc.data()
})))
))
} else {
setOrders([])
}
}, [user])
I am trying to emulate this function using the v9 modular style but am running into some issues.
if you are using a query there is no need to use the getDocs. You may check this documentation for examples.
Sample Code:
const collRef = collection(db,"users","user?.id","orders")
const orderedRef = query(colRef, orderBy("created", "desc"));
onSnapshot(orderedRef, (querySnapshot) => {
setOrders(
querySnapshot.docs.map((doc) => ({
id: doc.id,
data: doc.data(),
}))
);
});