{"version":3,"sources":["../../src/use-throttled-fn/index.ts"],"sourcesContent":["import { useCreation } from '../use-creation'\nimport { useLatest } from '../use-latest'\nimport { throttle } from '../utils/throttle'\n\nimport type { AnyFunc } from '../utils/basic'\nimport type { ThrottleOptions, ThrottledFn } from '../utils/throttle'\n\nexport interface UseThrottledFnOptions extends ThrottleOptions {}\n\n/**\n * A React Hook that helps to create a debounced function.\n */\nexport function useThrottledFn<T extends AnyFunc, P extends Parameters<T>>(\n  fn: T,\n  options: UseThrottledFnOptions = {},\n): ThrottledFn<T> {\n  const latest = useLatest({ fn })\n\n  return useCreation(() => {\n    const fnWrapper = ((...args: P) => latest.current.fn(...args)) as T\n    return throttle(fnWrapper, options)\n  }, [options])\n}\n"],"names":["useThrottledFn","fn","options","latest","useLatest","useCreation","fnWrapper","args","current","throttle"],"mappings":";;;;+BAYgBA;;;eAAAA;;;2BAZY;yBACF;wBACD;;;;;;;;;;;;;;;;;;;;;;;;;;AAUlB,SAASA,eACdC,EAAK;QACLC,UAAAA,iEAAiC,CAAC;IAElC,IAAMC,SAASC,IAAAA,oBAAS,EAAC;QAAEH,IAAAA;IAAG;IAE9B,OAAOI,IAAAA,wBAAW,EAAC;YACkBF;QAAnC,IAAMG,YAAa;6CAAIC;gBAAAA;;mBAAYJ,CAAAA,kBAAAA,OAAOK,OAAO,EAACP,EAAE,OAAjBE,iBAAkB,qBAAGI;;QACxD,OAAOE,IAAAA,kBAAQ,EAACH,WAAWJ;IAC7B,GAAG;QAACA;KAAQ;AACd"}