UNPKG

react-antd-admin-panel

Version:

Modern TypeScript-first React admin panel builder with Ant Design 6

122 lines 3.45 kB
import type { Key } from 'react'; /** * Pagination configuration for useList */ export interface UseListPagination { /** Current page number (1-indexed) */ current: number; /** Number of items per page */ pageSize: number; /** Total number of items (for server-side pagination) */ total?: number; } /** * Get configuration - either a URL string or an options object */ export interface UseListGetConfig { /** The URL to fetch data from */ url: string; /** Query parameters */ params?: Record<string, any>; /** Request headers */ headers?: Record<string, string>; } /** * Options for the useList hook */ export interface UseListOptions<T> { /** Data source configuration */ get: string | UseListGetConfig; /** Initial pagination settings */ pagination?: Partial<UseListPagination> | false; /** Initial filter values */ initialFilters?: Record<string, any>; /** Row key field or function */ rowKey?: string | ((record: T) => Key); /** Enable/disable the request (default: true) */ enabled?: boolean; /** Callback on success */ onSuccess?: (data: T[]) => void; /** Callback on error */ onError?: (error: Error) => void; /** Transform response data */ transform?: (response: any) => { data: T[]; total?: number; }; } /** * Return type for the useList hook */ export interface UseListResult<T> { /** The fetched data */ data: T[]; /** Loading state */ loading: boolean; /** Error if request failed */ error: Error | undefined; /** Refresh/refetch data */ refresh: () => Promise<void>; /** Current pagination state */ pagination: UseListPagination; /** Update pagination */ setPagination: (pagination: Partial<UseListPagination>) => void; /** Current filter values */ filters: Record<string, any>; /** Update filters */ setFilters: (filters: Record<string, any>) => void; /** Selected row keys */ selectedRowKeys: Key[]; /** Set selected row keys */ setSelectedRowKeys: (keys: Key[]) => void; /** Selected rows */ selectedRows: T[]; /** Clear selection */ clearSelection: () => void; /** Reset to initial state */ reset: () => void; } /** * useList - React hook for list/table data management * * @template T - Data item type * @param options - Hook options * @returns Hook result with data, loading, pagination, and control functions * * @example * ```tsx * // Basic usage * const { data, loading, refresh } = useList<User>({ * get: '/api/users', * }); * * // With pagination * const { data, pagination, setPagination } = useList<User>({ * get: '/api/users', * pagination: { pageSize: 10 }, * }); * * // With filters * const { data, filters, setFilters } = useList<User>({ * get: '/api/users', * initialFilters: { status: 'active' }, * }); * * // With selection * const { data, selectedRowKeys, setSelectedRowKeys, selectedRows } = useList<User>({ * get: '/api/users', * rowKey: 'id', * }); * * // With transform for custom API response * const { data } = useList<User>({ * get: '/api/users', * transform: (response) => ({ * data: response.items, * total: response.totalCount, * }), * }); * ``` */ export declare function useList<T extends object = any>(options: UseListOptions<T>): UseListResult<T>; //# sourceMappingURL=useList.d.ts.map