//#region src/useAsyncResource.d.ts type AsyncState = { status: 'idle' | 'loading' | 'refetching' | 'success' | 'error'; error: null | Error; data: T; }; type AsyncResult = AsyncState & { isLoading: boolean; load: () => void; }; type Options = { lazy?: boolean; asyncFnUsesExternalDeps?: boolean; externalDeps?: unknown[]; }; /** * React hook to manage the lifecycle of an async resource (fetching, loading, * error, success). * * Handles loading state, error state, and provides a `load` function to trigger * the async operation. By default, the async function runs on mount unless * `lazy: true` is passed. * * @example * const { data, isLoading, error, load } = useAsyncResource(() => * fetchUser(id), * ); * // Optionally, call `load()` to re-fetch or if using lazy mode * * @example * // Auto-refetch when dependencies change * const { data, isLoading, status } = useAsyncResource( * () => fetchUser(userId), * { asyncFnUsesExternalDeps: true }, * ); * // Will refetch automatically when userId changes, status becomes 'refetching' * * @param asyncFn - Function returning a Promise for the resource to load * @param options - Optional configuration object * @param options.lazy - If true, does not auto-load on mount * @param options.asyncFnUsesExternalDeps - If true, automatically re-fetches * when asyncFn changes * @param options.externalDeps - Array of dependencies that trigger refetch when * changed (similar to useEffect deps) * @returns Object with: * * - `status`: 'idle' | 'loading' | 'refetching' | 'success' | 'error' * - `error`: Error or null * - `data`: The loaded data or null * - `isLoading`: boolean (true if loading or refetching) * - `load`: function to trigger loading */ declare function useAsyncResource(asyncFn: () => Promise, { lazy, asyncFnUsesExternalDeps, externalDeps }?: Options): AsyncResult; //#endregion export { useAsyncResource };