Examinor
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. Examinor
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);
}
}```
Examinor
this is the function which gets the searched result
Examinor
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 to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Send Email Verification With REST
I am using REST to create a user on the server side after receiving form data from the client. After the account is successfully created i wanted to send the v...
- Use different email hosts for different ...
Hello, I have 2 projects and i want to be able to set up email templates in the projects. Both projects will have different email host configurations. I see ...