Skip to main content

useListContext

Returns the full ListContext state. Use when you need direct access to pagination, sort, filter, or selection state — for example to build a custom header, counter, or toolbar.

Signature

import { useListContext } from '@strato-admin/core';

function useListContext<T extends RaRecord>(): ListControllerResult<T>;

Must be called inside a ListContext (i.e. a descendant of <List>, <ReferenceManyField>, or <ArrayField>).

Return value

PropertyTypeDescription
dataT[]Current page of records
totalnumber | undefinedTotal records matching current filters
isPendingbooleantrue until data is fetched for the first time
isFetchingbooleantrue while a request is in flight
isLoadingbooleantrue on the very first load
errorError | nullData provider error, if any
pagenumberCurrent page (1-based)
perPagenumberPage size
setPage(page: number) => voidNavigate to a page
setPerPage(perPage: number) => voidChange page size
sort{ field: string; order: 'ASC' | 'DESC' }Current sort
setSort(sort) => voidChange sort
filterValuesobjectCurrent filter values
setFilters(filters, displayedFilters?) => voidUpdate filters
selectedIdsIdentifier[]IDs of selected records
onSelect(ids: Identifier[]) => voidReplace selection
onToggleItem(id: Identifier) => voidToggle one record's selection
onUnselectItems() => voidClear selection
resourcestringResource name
hasNextPageboolean | undefinedWhether a next page exists
hasPreviousPageboolean | undefinedWhether a previous page exists

Example

import { useListContext } from '@strato-admin/core';

function RecordCount() {
const { total, isPending } = useListContext();
if (isPending) return null;
return <span>{total} records</span>;
}