{"version":3,"file":"useAsyncBatchedCallback.cjs","names":["useAsyncBatcher"],"sources":["../../src/async-batcher/useAsyncBatchedCallback.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport { useAsyncBatcher } from './useAsyncBatcher'\nimport type { ReactAsyncBatcherOptions } from './useAsyncBatcher'\n\n/**\n * A React hook that creates a batched version of an async callback function.\n * This hook is a convenient wrapper around the `useAsyncBatcher` hook,\n * providing a stable, batched async function reference for use in React components.\n *\n * The batched async function will collect individual calls into batches and execute them\n * when batch conditions are met (max size reached, wait time elapsed, or custom logic).\n * The returned function always returns a promise that resolves with undefined (since the\n * batch function processes multiple items together).\n *\n * This hook provides a simpler API compared to `useAsyncBatcher`, making it ideal for basic\n * async batching needs. However, it does not expose the underlying AsyncBatcher instance.\n *\n * For advanced usage requiring features like:\n * - Manual batch execution\n * - Access to batch results and state\n * - Custom useCallback dependencies\n *\n * Consider using the `useAsyncBatcher` hook instead.\n *\n * @example\n * ```tsx\n * // Batch API requests\n * const batchApiCall = useAsyncBatchedCallback(async (requests: ApiRequest[]) => {\n *   const results = await Promise.all(requests.map(req => fetch(req.url)));\n *   return results.map(res => res.json());\n * }, {\n *   maxSize: 10,   // Process when 10 requests collected\n *   wait: 1000     // Or after 1 second\n * });\n *\n * // Use in event handlers\n * <button onClick={() => batchApiCall({ url: '/api/analytics', data: eventData })}>\n *   Track Event\n * </button>\n * ```\n */\nexport function useAsyncBatchedCallback<TValue>(\n  fn: (items: Array<TValue>) => Promise<unknown>,\n  options: ReactAsyncBatcherOptions<TValue, {}>,\n): (item: TValue) => Promise<void> {\n  const asyncBatchedFn = useAsyncBatcher(fn, options).addItem\n  return useCallback((item: TValue) => asyncBatchedFn(item), [asyncBatchedFn])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,wBACd,IACA,SACiC;CACjC,MAAM,iBAAiBA,wCAAgB,IAAI,QAAQ,CAAC;AACpD,gCAAoB,SAAiB,eAAe,KAAK,EAAE,CAAC,eAAe,CAAC"}