Describe the bug#
When using useInfiniteQuery , setting enabled: false still triggers the API call, which is unexpected behaviour.
Steps to reproduce#
Call an API using useInfiniteQuery and set enabled as false, still the api call will be triggered.
const {
data,
fetchNextPage,
isFetchingNextPage,
isFetching,
} = useInfiniteQuery({
queryKey: ['cueGalleryData'],
queryFn: ({pageParam = 0} ) => getUsers(pageParam),
enabled: false,
initialPageParam: 0,
staleTime: 30000,
getNextPageParam: (lastPage) => lastPage.nextPage,
});
async getUsers(pageParam) {
let payload = stores.userPayload;
payload['offset'] = pageParam payload.limit;
return new Promise(async (resolve, reject) => {
try {
const response = await this.post('/v2/users', payload);
resolve({
data: response.data.data.users,
currentPage: pageParam,
nextPage:
(pageParam + 1) payload.limit < response.data.data.total_rows
? pageParam + 1
: null,
});
} catch (error) {
reject(error);
}
});
}
Expected behavior#
When enabled is set to false, the API call should not occur. When it is set to true, the API call should be executed.
How often does this bug happen?#
Always
Platform#
Mac Os
TanStack Query version#
5.80.2
Thank you for filing this issue, but we need more information before looking into this.
Specifically, a minimal, standalone, runnable reproduction is needed - preferably with codesandbox or stackblitz.
We'll close this issue for now, but we'll certainly re-open it if there is a proper reproduction.