You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Handling useInfiniteQuery with filters and pagination
Problem Description
I'm implementing an infinite scroll list with filters using useInfiniteQuery. When filters change, I need to reset the pagination to start from page 1, but I'm having trouble managing the page state properly.
Current Implementation
constquery=useInfiniteQuery({key: ()=>["elements",{search: filters.search,tags: Array.from(filters.tags)}],query: async({ pagination })=>{if(pagination.isLastPage){returnnull;}returnusersClient.getRelationElements<ElementResource,ElementPhotoResource[]>(authStore.user!.id,(builder)=>{if(filters.search.length>2){builder.filter(newFilter("fullTitle",Operator.CONTAINS,filters.search));}if(filters.tags.size>0){builder.filter(newFilter("tags",Operator.IN,Array.from(filters.tags)));}returnbuilder.include(["photos"]).page(nextPage.value,24);});},// ... rest of the implementation});
Current Behavior
I have a nextPage ref that I try to reset when filters change
I'm using watchDeep to detect filter changes and reset the page
The infinite scroll works correctly for initial load and subsequent pages
However, when filters change, the pagination doesn't properly reset
Expected Behavior
When filters change:
Reset pagination to page 1
Clear existing data
Load new data with the updated filters
Allow infinite scroll to continue from the new filtered results
Questions
What's the recommended way to handle filter changes with useInfiniteQuery?
Should I be using a different approach to manage the page state?
Is there a built-in way to reset the query when filters change?
Additional Context
Using Vue 3 with Pinia Colada
Implementing an infinite scroll list with search and tag filters
Need to maintain smooth user experience when filters change
Any guidance on the best practices for this scenario would be greatly appreciated!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Handling useInfiniteQuery with filters and pagination
Problem Description
I'm implementing an infinite scroll list with filters using
useInfiniteQuery
. When filters change, I need to reset the pagination to start from page 1, but I'm having trouble managing the page state properly.Current Implementation
Current Behavior
nextPage
ref that I try to reset when filters changewatchDeep
to detect filter changes and reset the pageExpected Behavior
When filters change:
Questions
useInfiniteQuery
?Additional Context
Any guidance on the best practices for this scenario would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions