if (startAfterDoc) {
q = query(collection(db, 'listings'), orderBy("id","desc"), startAfter(startAfterDoc), limit(4));
console.log(q)
} else {
q = query(collection(db, 'listings'), orderBy("id","desc"), limit(3));
}
For startAfterDoc
I'm using whole doc as input.
Image when startafterdoc
not defined:
Image when startafterdoc
is defined:
Got the solution I passed the whole document in startAfter, but then I realized I was ordering by id. When I passed the document id instead, it worked perfectly
if (startAfterDoc) {
q = query(collection(db, 'listings'), orderBy("id","desc"), startAfter(startAfterDoc.id), limit(4));
} else {
q = query(collection(db, 'listings'), orderBy("id","desc"), limit(3));
}