Query with Pagination + Filters
I'm implementing pagination with filters using React Query, and I've hit an interesting UX issue. Here's the scenario:
continue...
2 Replies
genetic-orangeOP•13mo ago
The issue is the sequence of events when filters change:
1. User applies new filter -> the effect runs
2. New query starts fetching
3. Page resets to 1
4. User sees page 1 of OLD results
5. New filtered results arrive and replace the view
This creates a noticeable flicker: OLD_DATA (page N) → OLD_DATA (page 1) → NEW_DATA (page 1)
Any ideas how to handle this properly?
is there any good example of data with pagination and filters working flawlessly?
Thank you!
@TkDodo 🔮 I'd really appreciate your insights on this, as I'm completely stuck...!
fascinating-indigo•13mo ago
triggering the
setPageNumber in an useEffect is a bad pattern, you wait for filterState to change in one render, then wait for page to change in another, instead do
to batch the 2 set states, which should result in only 1 new query being triggered
(i used ...args because I do not know what setFilters and setFilterState expect, I suppose it is a filter object)