The options object for configuring the hook.
Optional
apiAdditional options to pass to the API client.
The pagination configuration.
page
- An array where the first element is the name of the query parameter that represents the page number. The page number will automatically increment with each subsequent request.
per_page
- An array where the first element is the name of the query parameter that represents the number of items per page, and the second element is the value to be used for that parameter.
For example:
{ page: ['page_number'], per_page: ['count', 20] }
will result in query parameters like ?page_number={{pageParam}}&count=20
.Optional
params?: Record<string, any>Dynamic query parameters for the API request.
Optional
queryAdditional options to configure the useInfiniteQuery
hook.
The resource path and any static parameters for the API request.
The result of the useInfiniteQuery
hook.
A hook that helps you fetch a infinite list of resources.
The hook uses
useInfiniteQuery
from@tanstack/react-query
to fetch data and cache it. It accepts various query options and performs an API request to fetch a list of resources based on the providedresource
andparams
. The hook supports additional query parameters and custom API client parameters.If a custom
queryFn
is provided, it will be used to perform the query; otherwise, the default API client method will be used. ThequeryKey
is constructed based on the resource path and additional parameters to ensure proper caching and refetching.By default, this hook sets the following options:
initialPageParam
: 1getNextPageParam
: Calculates the next page number based on the length of the data in the last page.getPreviousPageParam
: Calculates the previous page number, but prevents it from going below 1.These default options can be overridden if necessary.
Example