Skip to main content

useGetAll

Fetches every record of a resource, walking the pages for you.

Use it where a complete set is genuinely needed — a select box, an export, a chart. For anything the user browses, use React Admin's paginated useGetList instead: this hook keeps requesting until the resource is exhausted.

Signature​

import {useGetAll} from 'habarico';

const {data, total, isLoading, isError, refetch} = useGetAll<Product>('eshop/product', {
sort: {field: 'name', order: 'ASC'},
filter: {is_available: true},
perPage: 50,
});

Parameters​

NameTypeDefaultDescription
resource (required)string—Resource in "service/resource" form
params.sortSortPayload{field: 'id', order: 'DESC'}Sort passed to every page request
params.filterDataType{}Filter passed to every page request
params.perPagenumber50Page size — how many requests the walk takes
params.metaDataType—Passed through to the data provider, e.g. field selection
optionsUseQueryOptions—React Query options, e.g. enabled

Returns​

The React Query result, with data and total lifted to the top level:

NameTypeDescription
dataRecordType[] | undefinedAll records, in the requested order
totalnumber | undefinedNumber of records fetched
isLoading / isError / refetch—Standard React Query fields

Example​

const {data: categories = [], isLoading} = useGetAll<Category>('eshop/category', {
sort: {field: 'name', order: 'ASC'},
});
caution

The query key covers resource, sort, filter and perPage — not meta. Two calls that differ only in meta share one cache entry, so pass a distinct filter (or your own queryKey via options) when the field selection has to differ.

See also​

  • DataProvider — the getList call this hook repeats
  • useExporter — exporting a list on the backend instead of fetching it