I'm trying to implement Pagination using Firebase. I've tried with the code from related issue here:
The methods have changed slightly but my code I'm using (based on your recommendation) is below. It works for the first fetch, on page load. But pressing the next arrow doesn't fetch any more users. The table data remains the same.
Please help!
const TIMESTAMP_KEY = "createdAt"
await db
.firestore()
.collection("users")
.orderBy(TIMESTAMP_KEY, "desc")
.startAfter(firestore.Timestamp.fromDate(new Date(cursor)))
.limit(table1.pagination.pageSize || 27)
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
const values = doc.data();
let createdAtValue = values[TIMESTAMP_KEY];
createdAtValue = new Date(createdAtValue);
data.push({
...values,
[TIMESTAMP_KEY]: createdAtValue,
});
});
});
return data;