/** * Configuration options for the `useResource` hook. * * @template T The type of data returned by the fetcher. */ export interface ResourceConfig { key: string; fetcher: (signal: AbortSignal) => Promise; enabled?: boolean; initialData?: T | (() => T); cache?: "memory" | "shared" | "indexeddb" | false; namespace?: string; persist?: { exclude?: (keyof T)[]; store?: string; }; staleTime?: number; gcTime?: number; retry?: number | ((error: unknown, attempt: number) => boolean); retryDelay?: number | ((attempt: number) => number); keepPreviousData?: boolean; refetchOnFocus?: boolean; refetchOnReconnect?: boolean; selector?: (data: T | undefined) => unknown; equalityFn?: (a: unknown, b: unknown) => boolean; onSuccess?: (data: T) => void; onError?: (error: Error) => void; onMutate?: (patch: unknown) => void; onRefresh?: () => void; onInvalidate?: () => void; onRetry?: (attempt: number, error: Error) => void; } export interface ResourceState { data: T | undefined; error: Error | undefined; status: "idle" | "loading" | "success" | "refreshing" | "error"; updatedAt: number | null; createdAt: number | null; retryCount: number; } /** * The state and methods returned by the `useResource` hook. * * @template T The type of data managed by the resource. */ export interface Resource extends ResourceState { loading: boolean; fetching: boolean; isStale: boolean; refresh(): Promise; invalidate(): void; reset(): void; set(value: T): void; mutate(updater: (current: T | undefined) => T): void; select(selector: (data: T | undefined) => R, equalityFn?: (a: R, b: R) => boolean): R; } export declare function __resetResourceRegistryForTests(): void; /** * A highly optimized hook for data fetching, caching, and state management. * Provides automatic background fetching, polling, persistence, tab-synchronization, and optimistic mutations. * * @template T The type of data managed by the resource. * @param config Configuration options for the resource, including the unique key and fetcher function. * @returns The current state of the resource, along with methods to refresh, mutate, and invalidate it. */ export declare function useResource(config: ResourceConfig): Resource; export declare namespace useResource { var compose: typeof useResourceCompose; var clear: (key: string) => void; var clearAll: () => void; } export declare function useResourceCompose>, R>(config: { key: string; deps: TDeps; selector: (values: { [K in keyof TDeps]: TDeps[K]["data"]; }) => R; equalityFn?: (a: R, b: R) => boolean; }): Resource;