redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

Add refetchCachedPages option for infinite query

Open rossmartin opened this issue 5 months ago • 3 comments

This refetchCachedPages option allows an infinite query to NOT refetch all pages in the cache when a refetch happens. By default it is true and uses the existing behavior.

This is based on what was mentioned in the discussion here - https://github.com/reduxjs/redux-toolkit/discussions/5011. It's also based on this resolved issue here - https://github.com/reduxjs/redux-toolkit/issues/4920

We want the ability to opt out of this behavior at this level. We don't want to have to reset the pages/pageParams for a query when args change or during a refetch.

Here is an example of how it can be used:

    getPosts: builder.infiniteQuery<GetPostsResponse, GetPostsRequest, string | undefined>({
      infiniteQueryOptions: {
        // ...
        refetchCachedPages: false,
      },
      // ...
    }),  
Screenshot 2025-06-18 at 5 03 08 PM

rossmartin avatar Jun 18 '25 22:06 rossmartin