UNPKG

ra-core

Version:

Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React

53 lines 2.33 kB
import { FilterPayload, RaRecord, SortPayload } from '../../types'; import { ListControllerResult } from './useListController'; /** * Handle filtering, sorting and pagination on local data. * * Returns the data and callbacks expected by <ListContext>. * * @example * const data = [ * { id: 1, name: 'Arnold' }, * { id: 2, name: 'Sylvester' }, * { id: 3, name: 'Jean-Claude' }, * ] * * const MyComponent = () => { * const listContext = useList({ data }); * return ( * <ListContextProvider value={listContext}> * <Datagrid> * <TextField source="id" /> * <TextField source="name" /> * </Datagrid> * </ListContextProvider> * ); * }; * * @param {UseListOptions} props * @param {RaRecord[]} props.data An array of records * @param {Boolean} props.isFetching: Optional. A boolean indicating whether the data is being loaded * @param {Boolean} props.isLoading: Optional. A boolean indicating whether the data has been loaded at least once * @param {Error | String} props.error: Optional. The error if any occurred while loading the data * @param {Object} props.filter: Optional. An object containing the filters applied on the data * @param {Number} props.page: Optional. The initial page index * @param {Number} props.perPage: Optional. The initial page size * @param {SortPayload} props.sort: Optional. The initial sort (field and order) * @param {filterCallback} prop.filterCallback Optional. A function that allows you to make a custom filter */ export declare const useList: <RecordType extends RaRecord<import("../../types").Identifier> = any, ErrorType = Error>(props: UseListOptions<RecordType, ErrorType>) => UseListValue<RecordType, ErrorType>; export interface UseListOptions<RecordType extends RaRecord = any, ErrorType = Error> { data?: RecordType[]; error?: ErrorType | null; filter?: FilterPayload; isFetching?: boolean; isLoading?: boolean; isPending?: boolean; page?: number; perPage?: number; sort?: SortPayload; resource?: string; filterCallback?: (record: RecordType) => boolean; } export type UseListValue<RecordType extends RaRecord = any, ErrorType = Error> = ListControllerResult<RecordType, ErrorType>; //# sourceMappingURL=useList.d.ts.map