invertase / invertase/tanstack-query-firebase

Cannot get previousPage when using useFirestoreInfiniteQuery or useFirestoreInfiniteQueryData

Open
#55 0 comments 0 reactions 0 assignees View on GitHub
react-query-firebase
Dominant language
TypeScript
Stars
462
Forks
69
PR merge metrics
No merged PRs in 30d

Description

Looks like the code inside getPreviousPageParam is not even being executed.

Example:
``` javascript
const ordersQuery = query(
collection(firestore, "orders") as CollectionReference,
orderBy("createdAt"),
limit(1)
);
const {
data,
hasPreviousPage,
hasNextPage,
fetchPreviousPage,
fetchNextPage,
} = useFirestoreInfiniteQueryData(
["getOrders"],
ordersQuery,
(snapshot) => {
const lastDocument = snapshot[snapshot.length - 1];
if (!lastDocument) return;
return query(ordersQuery, startAfter(lastDocument.createdAt));
},
{},
{
getPreviousPageParam: (firstPage) => {
const firstOrder = firstPage[0];
return query(ordersQuery, endBefore(firstOrder.createdAt));
},
}
);
```
The result is the same when loading the component and after click a few times in next page button.
`console.log(hasPreviousPage, hasNextPage);`

![image](https://user-images.githubusercontent.com/14021153/179902027-95a7a06f-d4b7-4f89-96e2-3710c35e3533.png)

Also tried to console.log inside getPreviousPageParam and nothing happens.

I'm I doing something wrong?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.