multiple filters, infinite scroll and a search input
I need to write a useInfiniteQuery where search filters can be unset, the query key will be just the: [entity], there can be one filter: [entity, filter], or multiple filters selected: [entity, ??], and with an optional search string. All using pagination and infinite scroll.
What should I put as my query key for multiple filters or is it better to change the backend query dynamically and keep adding the newer results to the same query cache while storing old results?
Can someone show me the best approach to this problem?
Thanks
4 Replies
extended-salmon•2y ago
All dependencies go into the query key!
afraid-scarletOP•2y ago
So multiple filters by multiple categories with a text search should have the query key: [entity, categoryOne, categoryTwo, categoryThree, searchTerm] for example?
I want all the downloaded results to be visible when all filters are then removed, so key [entity] should also contain everything downloaded when filters were applied to the query, no matter how many filters or what type of filter (search and select categories) were applied then removed
extended-salmon•2y ago
Your query function should handle that
afraid-scarletOP•2y ago
Sorry I don't understand. So multiple filters by multiple categories with a text search should have the query key: [entity, categoryOne, categoryTwo, categoryThree, searchTerm] for example? Or no?