{"version":3,"file":"useAsyncDebouncedCallback.cjs","names":["useAsyncDebouncer"],"sources":["../../src/async-debouncer/useAsyncDebouncedCallback.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport { useAsyncDebouncer } from './useAsyncDebouncer'\nimport type { ReactAsyncDebouncerOptions } from './useAsyncDebouncer'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\n\n/**\n * A React hook that creates a debounced version of an async callback function.\n * This hook is a convenient wrapper around the `useAsyncDebouncer` hook,\n * providing a stable, debounced async function reference for use in React components.\n *\n * The debounced async function will only execute after the specified wait time has elapsed\n * since its last invocation. If called again before the wait time expires, the timer\n * resets and starts waiting again. The returned function always returns a promise\n * that resolves or rejects with the result of the original async function.\n *\n * This hook provides a simpler API compared to `useAsyncDebouncer`, making it ideal for basic\n * async debouncing needs. However, it does not expose the underlying AsyncDebouncer instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution/error state\n * - Custom useCallback dependencies\n *\n * Consider using the `useAsyncDebouncer` hook instead.\n *\n *\n * @example\n * ```tsx\n * // Debounce an async search handler\n * const handleSearch = useAsyncDebouncedCallback(async (query: string) => {\n *   const results = await fetchSearchResults(query);\n *   return results;\n * }, {\n *   wait: 500 // Wait 500ms between executions\n * });\n *\n * // Use in an input\n * <input\n *   type=\"search\"\n *   onChange={e => handleSearch(e.target.value)}\n * />\n * ```\n */\nexport function useAsyncDebouncedCallback<TFn extends AnyAsyncFunction>(\n  fn: TFn,\n  options: ReactAsyncDebouncerOptions<TFn, {}>,\n): (...args: Parameters<TFn>) => Promise<ReturnType<TFn>> {\n  const asyncDebouncedFn = useAsyncDebouncer(fn, options).maybeExecute\n  return useCallback(\n    (...args) => asyncDebouncedFn(...args) as Promise<ReturnType<TFn>>,\n    [asyncDebouncedFn],\n  )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,SAAgB,0BACd,IACA,SACwD;CACxD,MAAM,mBAAmBA,4CAAkB,IAAI,QAAQ,CAAC;AACxD,gCACG,GAAG,SAAS,iBAAiB,GAAG,KAAK,EACtC,CAAC,iBAAiB,CACnB"}