UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

47 lines (46 loc) 1.74 kB
import type { FilterValue } from '../FilterContext'; /** * Hook to consume filter state from anywhere in the component tree. * Linked to a Filter.Root by id via useSharedState. */ export declare function useFilter(id: string): { filters: Record<string, FilterValue>; search: string; hasActiveFilters: boolean; resetFilters: () => void; removeFilter: (filterKey: string) => void; }; /** * Hook for use inside the Filter.Root tree. * Gives direct access to the filter context for building custom filters. */ export declare function useFilterContext(): { setFilter: (filterKey: string, value: FilterValue | undefined) => void; getFilter: (filterKey: string) => FilterValue | undefined; removeFilter: (filterKey: string) => void; resetFilters: () => void; commitFilters: () => void; revertFilters: () => void; filters: Record<string, FilterValue>; search: string; hasActiveFilters: boolean; }; export type FilterAsyncOptions<T> = { /** Seed data used for the initial render before the first fetch completes. */ initialData?: T; /** Delay in milliseconds before executing the fetcher after a state change. Useful for reducing API calls while the user is typing. */ debounce?: number; }; /** * Hook for async data fetching linked to a Filter.Root. * Handles loading state, race conditions, and syncs resultLoading/resultCount * to the shared filter state so Filter.Content picks them up. */ export declare function useFilterAsync<T>(id: string, fetcher: (params: { filters: Record<string, FilterValue>; search: string; }) => Promise<T>, options?: FilterAsyncOptions<T>): { data: T | undefined; loading: boolean; error: Error | undefined; };