{"version":3,"file":"useBatchedCallback.cjs","names":["useBatcher"],"sources":["../../src/batcher/useBatchedCallback.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport { useBatcher } from './useBatcher'\nimport type { ReactBatcherOptions } from './useBatcher'\n\n/**\n * A React hook that creates a batched version of a callback function.\n * This hook is essentially a wrapper around the basic `batch` function\n * that is exported from `@tanstack/pacer`,\n * but optimized for React with reactive options and a stable function reference.\n *\n * The batched 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 *\n * This hook provides a simpler API compared to `useBatcher`, making it ideal for basic\n * batching needs. However, it does not expose the underlying Batcher instance.\n *\n * For advanced usage requiring features like:\n * - Manual batch execution\n * - Access to batch state and metrics\n * - Custom useCallback dependencies\n *\n * Consider using the `useBatcher` hook instead.\n *\n * @example\n * ```tsx\n * // Batch analytics events\n * const trackEvents = useBatchedCallback((events: AnalyticsEvent[]) => {\n *   sendAnalytics(events);\n * }, {\n *   maxSize: 5,    // Process when 5 events collected\n *   wait: 2000     // Or after 2 seconds\n * });\n *\n * // Use in event handlers\n * <button onClick={() => trackEvents({ type: 'click', target: 'button' })}>\n *   Click me\n * </button>\n * ```\n */\nexport function useBatchedCallback<TValue>(\n  fn: (items: Array<TValue>) => void,\n  options: ReactBatcherOptions<TValue, {}>,\n): (item: TValue) => void {\n  const batchedFn = useBatcher(fn, options).addItem\n  return useCallback((item: TValue) => batchedFn(item), [batchedFn])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,mBACd,IACA,SACwB;CACxB,MAAM,YAAYA,8BAAW,IAAI,QAAQ,CAAC;AAC1C,gCAAoB,SAAiB,UAAU,KAAK,EAAE,CAAC,UAAU,CAAC"}