Capítulo 64 de 80
Superset of useQuery's options/returns — the reference companion to the Infinite Queries guide, listing every field precisely (including a return-shape difference in isRefetching that excludes next/previous-page fetches, not just the initial one).
useQuery: initialPageParam (seed value for the first page); getNextPageParam(lastPage, allPages, lastPageParam, allPageParams) (returns the next pageParam, or undefined/null for "no more pages" — required). getPreviousPageParam has the mirrored signature for bi-directional lists, optional unless bi-directional.maxPages: caps stored/refetched pages — when the cap is hit, fetching a new page evicts the oldest page from the opposite end (requires both getNextPageParam and getPreviousPageParam properly defined once maxPages > 0, so eviction/refetch can work in both directions).data.pages/data.pageParams (arrays, same length, paired by index); fetchNextPage/fetchPreviousPage (trigger loading more, both accept { cancelRefetch } — default true, meaning repeated calls always invoke queryFn again and ignore earlier in-flight results; false makes repeated calls no-ops until the first resolves); hasNextPage/hasPreviousPage; isFetchingNextPage/isFetchingPreviousPage; isFetchNextPageError/isFetchPreviousPageError.isRefetching redefinition: for infinite queries, isRefetching excludes both the initial fetch and next/previous-page fetches — isFetching && !isPending && !isFetchingNextPage && !isFetchingPreviousPage. This is stricter than the plain useQuery definition.fetchNextPage/fetchPreviousPage can interfere with the query's normal background-refetch behavior if not gated — guard calls with conditions like hasNextPage && !isFetching, and trigger them only from real user actions (scroll-end, button click), not arbitrarily.| Return field (infinite-specific) | Meaning |
|---|---|
data.pages / data.pageParams | Parallel arrays of fetched page data and their params |
fetchNextPage(opts) / fetchPreviousPage(opts) | Load more; cancelRefetch (default true) controls overlap behavior |
hasNextPage / hasPreviousPage | Whether getNextPageParam/getPreviousPageParam returned a usable value |
isFetchingNextPage / isFetchingPreviousPage | Currently loading more in that direction |
isFetchNextPageError / isFetchPreviousPageError | That direction's most recent load-more attempt failed |
getNextPageParam is mandatory (unlike useQuery, which needs nothing infinite-specific) — an infinite query without it won't type-check or run correctly.isRefetching here is stricter than in useQuery — it's specifically "background refetch, not initial load, not next/previous page load."fetchNextPage/fetchPreviousPage calls on hasNextPage/hasPreviousPage and !isFetching to avoid interfering with the library's own refetch scheduling.