Infinite scrolling with filters and optimistic updates using rtk query #3845
Replies: 1 comment 1 reply
-
Hi, so my story is that someone suggested me to use RTK-Query instead of React-Query and after some exploration I selected RTK-Query for multiple plus points of this lib. However, now my client wants me to add infinite scroll in all listing APIs and I did tried the suggestion in one of the discussions but I'm facing same problem as yours. The infinite scroll only works if you only want to list the data, and it is not working (basically the invalidate cache logic) when user updates a record. So, I'm here adding this comment to get this discussion some attention from the responsible party #developers of RTK-Query. I really want to keep on using RTK-Query, the only problem is Infinite Scroll. The project I've implemented this in is now too big that I cannot change it to react-query. 😅 So please... ✌🏻 |
Beta Was this translation helpful? Give feedback.
-
I am using rtk query and have an implementation for infinite scrolling, this logic is implemented through offset and limit, however I also have filters and when changing any of the filters I have to reset the offset to 0.
I use merge, serializeQueryArgs and forceRefetch. For serializeQueryArgs I use the arguments of this query, excluding the offset and thus when any of the filters change I get a cache update
I also use optimistic updates because the data I display contains the logic of adding to favorites and I want the user to immediately see the result without reloading the entire list and resetting the filters
I'm having a conflict between my two approaches because when I make the query parameters the key for the cache then the key changes dynamically and optimistic updates don't work.
Conversely, if I use a static key for the cache such as endpointName, then resetting the cache when changing filters will not work
The question is whether it is possible to do what I want and if so, what should be paid attention to?
Beta Was this translation helpful? Give feedback.
All reactions