Description
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