Im retrieving a data from firebase collection named matches,im querying data based on user.uid .but im getting a error FirebaseError: Expected type 'Ta', but it was: a custom oh object
import { View, Text } from "react-native";
import React, { useEffect, useState } from "react";
import useAuth from "../hooks/useAuth";
import { onSnapshot, query, where } from "firebase/firestore";
import { db } from "../firebase";
const Chatlist = () => {
const [matches, setMatches] = useState([]);
const { user } = useAuth();
useEffect(
() =>
onSnapshot(
query(db, "matches"),
where("userMatched", "array-contains", user.uid)
),
(snapshot) =>
setMatches(
snapshot.docs.map((doc) => ({
id: doc.id,
...doc.data(),
}))
),
[user]
);
CodePudding user response:
The query constraints should be passed in query()
function itself. Also onSnapshot
2nd parameter is the callback function. Try refactoring the code as shown below:
useEffect(() => {
if (user) {
const q = query(collection(db, "matches"), where("userMatched", "array-contains", user.uid))
return onSnapshot(q, (snapshot) => {
setMatches(
snapshot.docs.map((doc) => ({
id: doc.id,
...doc.data(),
}))
)
})
} else {
console.log("No user logged in")
}
}, [user])