is there a way to pass the data that has been retrieved when fetchNextPage is being executed?
i wanted to use the document data (retrieved from the initial fetch) as my cursor instead of incementing or decrementing one by one.
1 messages · Page 1 of 1 (latest)
is there a way to pass the data that has been retrieved when fetchNextPage is being executed?
i wanted to use the document data (retrieved from the initial fetch) as my cursor instead of incementing or decrementing one by one.
I don't understand the question ..
I'm working with useInfiniteQuery in React Query and want to leverage retrieved data as a cursor for infinite scroll pagination. This approach involves using the last item in the fetched data array to indicate the starting point for the next request, essentially requesting documents after the last one received. However, I'm encountering challenges in implementing this with React Query.
my function looks like this
const fetchThoughts = async (lastPost?: Timestamp): Promise<IThought[]> => {
let q = query(
thoughtsCollectionRef,
orderBy('createdAt', 'desc'),
limit(THOUGHTS_PER_PAGE)
);
if (lastPost) {
q = query(q, startAfter(lastPost));
}
const querySnapshot = await getDocs(q);
return querySnapshot.docs.map((doc) => ({
...(doc.data() as Omit<IThought, 'id'>),
id: doc.id,
}));
};