
I want to get the searched result in pagination but i am not getting that so is it possible to paginate search results
TL;DR
Developers want to implement infinite scroll pagination with React Query using Query.Search. The issue seems to be with fetching the search results in pagination. The code provided shows the use of `useInfiniteQuery` and `authservice.getInfiniteUserResult` to fetch the data. The solution may involve debugging the `useGetInfinityUserSearch` and `getInfiniteUserResult` functions to ensure proper handling of pagination.
TypeScript
getInfiniteUserResult=async({pageParam,id}: { pageParam: number, id:string })=>{
const queries: any[] = [Query.orderDesc("$updatedAt"), Query.limit(6),Query.search('userName', id)];
if (pageParam) {
queries.push(Query.cursorAfter(pageParam.toString()));
}
try {
console.log(id);
let posts = await this.database.listDocuments(
conf.DATABASE_ID,
conf.USER,
queries
);
if (!posts) throw Error;
console.log(posts);
return posts;
} catch (error) {
console.log(error);
}
}```

this is the function which gets the searched result

TypeScript
export const useGetInfinityUserSearch = (id:string) => {
return useInfiniteQuery({
queryKey: [QUERY_KEYS.GET_INFINITE_USER_SEARCH],
queryFn: ({ pageParam }) =>{
console.log(id);
return authservice.getInfiniteUserResult({id:id, pageParam:pageParam})
},
getNextPageParam: (lastPage ) => {
if (lastPage && lastPage.documents.length === 0) {
return null;
}
const lastId = lastPage?.documents[lastPage.documents.length - 1].$id;
console.log(lastPage);
return lastId;
},
});
};```
This is react-query
Recommended threads
- how many Teams can be created?
I am creating an app where I will let users create groups. This could mean there will be many groups created by user, to isolate those groups properly I am thin...
- React native app login via Safari
Hi! I deployed for debug my React Native app in web, chrome everythink works well but in safari on mac and ios I cant login. I found this one error in safari co...
- Error Generation of certification for cu...
Hi, I tried to connect a custom domain, this worked but creating the certification afterwards fails with the following error: ```txt Failed to create TLS subsc...
