Description
Currently, I am implementing infinite scroll feature using your infinite query and I successfully integrated it. But, there is one issue. The desired behaviour is to refetch only the first page when user initiates the refetch action. This doesn't happen and all pages are refetched.
This is the query:
import { queryApi } from 'config/rtkQuery';
import { CatchesFeedItem } from './types';
const url = 'public_trips';
type GetCatchesFeedArgumentsType = {
page?: number;
per_page?: number;
};
type MetaType = {
totalCount: number;
pageCount: number;
currentPage: number;
perPage: number;
};
const catchesFeedApi = queryApi.injectEndpoints({
endpoints: (build) => ({
getCatchesFeed: build.infiniteQuery<
{ data: CatchesFeedItem[]; meta: MetaType },
GetCatchesFeedArgumentsType,
number
>({
infiniteQueryOptions: {
initialPageParam: 1,
getNextPageParam: (lastPage, allPages, lastPageParam) => {
return lastPageParam + 1;
},
},
query: ({ pageParam }) => ({
url: url,
method: 'get',
params: {
include: 'meta',
page: pageParam || 1,
per_page: 10,
},
}),
transformResponse: (response: CatchesFeedItem[], meta: MetaType) => {
return { data: response, meta: meta };
},
providesTags: ['CatchesFeed'],
}),
}),
overrideExisting: true,
});
export const { useGetCatchesFeedInfiniteQuery } = catchesFeedApi;
In the documentation there is this sentence
If the cache entry is ever removed and then re-added, it will start with only fetching the initial page.
but I don't know what it means exactly and how to force this behaviour. Can you help me with this? I tried to invalidate the provided that and that doesn't work. Also, when I tried to reset the whole app state it worked but that's the overkill because I don't want to reset the whole state, just this small fraction.