-1

Here's my scenario, I have an infinite scroll list in React Native that I implemented with RTK Query using merge and forceRefetch, each time the user scrolls down to the bottom of the list I increment the current page number which will trigger a new page fetch with a new offset param passed to the query. The newly fetched items are simply pushed to the end of the already existing list.

My issue is when I try to invalidate such a cache from another "Screen".

Ideally, after the mutation succeeds I want to invalidate this entire cache setting back the current page number to zero which will fetch only the first page so that if the current state of my cache contained a merged list of X pages it should now contain only the first page of let's say 20 items.

Now when I try to implement that using invalidatesTags it always uses the last offset param passed to it, even if I reset the current page number back to zero.

So I'm asking if there's a way we can invalidate the cache with new params? In my case I would like to invalidate the cache with a current page number set to zero so that the offset would point to the first page.

Any insight is much appreciated.

Drew Reese
  • 165,259
  • 14
  • 153
  • 181
abdou-tech
  • 687
  • 1
  • 8
  • 16
  • 2
    Your `invalidatesTags` function is just a function that you write - you can have it validate whatever you want there, including completely different tags or ids from -1000 to 1000000000000. It's completely up to you what you return there. – phry Mar 20 '23 at 18:25

1 Answers1

0

I am not sure if setting the current page number to zero is the same thing. But there must be a pageSize property in your infinite query. I think altering this property might work for you. the name is pageSize but it is also addressing pageNum. It is a little bit confusing for me for the first time.

Cemal
  • 73
  • 7