react-query-firebase icon indicating copy to clipboard operation
react-query-firebase copied to clipboard

Cannot get previousPage when using useFirestoreInfiniteQuery or useFirestoreInfiniteQueryData

Open Drealler opened this issue 3 years ago • 0 comments

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

Example:

 const ordersQuery = query(
    collection(firestore, "orders") as CollectionReference<Order>,
    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

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

I'm I doing something wrong?

Drealler avatar Jul 20 '22 05:07 Drealler