redux-toolkit
redux-toolkit copied to clipboard
Add refetchCachedPages option for infinite query
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,
},
// ...
}),