{"version":3,"file":"useThrottledCallback.cjs","names":["useThrottler"],"sources":["../../src/throttler/useThrottledCallback.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport { useThrottler } from './useThrottler'\nimport type { ReactThrottlerOptions } from './useThrottler'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * A React hook that creates a throttled version of a callback function.\n * This hook is essentially a wrapper around the basic `throttle` function\n * that is exported from `@tanstack/pacer`,\n * but optimized for React with reactive options and a stable function reference.\n *\n * The throttled function will execute at most once within the specified wait time period,\n * regardless of how many times it is called. If called multiple times during the wait period,\n * only the first invocation will execute, and subsequent calls will be ignored until\n * the wait period has elapsed.\n *\n * This hook provides a simpler API compared to `useThrottler`, making it ideal for basic\n * throttling needs. However, it does not expose the underlying Throttler instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - Custom useCallback dependencies\n *\n * Consider using the `useThrottler` hook instead.\n *\n * @example\n * ```tsx\n * // Throttle a window resize handler\n * const handleResize = useThrottledCallback(() => {\n *   updateLayoutMeasurements();\n * }, {\n *   wait: 100 // Execute at most once every 100ms\n * });\n *\n * // Use in an event listener\n * useEffect(() => {\n *   window.addEventListener('resize', handleResize);\n *   return () => window.removeEventListener('resize', handleResize);\n * }, [handleResize]);\n * ```\n */\nexport function useThrottledCallback<TFn extends AnyFunction>(\n  fn: TFn,\n  options: ReactThrottlerOptions<TFn, {}>,\n): (...args: Parameters<TFn>) => void {\n  const throttledFn = useThrottler(fn, options).maybeExecute\n  return useCallback((...args) => throttledFn(...args), [throttledFn])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,qBACd,IACA,SACoC;CACpC,MAAM,cAAcA,kCAAa,IAAI,QAAQ,CAAC;AAC9C,gCAAoB,GAAG,SAAS,YAAY,GAAG,KAAK,EAAE,CAAC,YAAY,CAAC"}