Reputation: 1
i'm trying to make firebase paginate, it throws an error: Type ""limitToFirst"" cannot be satisfied for type "QueryConstraintType". what am i doing wrong?
`
useEffect(() => {
const getData = async () => {
const q = query(collection(db, "goods"), where("tags", "array-contains-any", ["Хит"]), limit(5), startAt(5))
const documentSnapshots = await getDocs(q)
documentSnapshots.forEach((el) => {
console.log(el.data());
})
}
getData()
}, [])
`
Upvotes: 0
Views: 499
Reputation: 598765
Given startAt(5)
you seem to think that startAt
takes an offset, while Firestore's pagination is actually based on a query cursor: knowing details about the specific document you want to start at.
This means that you need to pass either the DocumentSnapshot
you want to start at, or all sorted field values and the document ID of the document you want to start at to the startAt
operation. So startAt
expects either a DocumentSnapshot
or an array of values, and you're passing neither of those.
For more on this, I recommend checking out the Firestore documentation on implementing pagination using query cursors.
Upvotes: 1