UNPKG

1.19 kBSource Map (JSON)View Raw
1{"version":3,"sources":["useThrottledFn.js"],"names":["defaultOptions","leading","trailing","useThrottledFn","fn","wait","options","dependencies","throttled"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA,IAAMA,cAAc,GAAG;AACrBC,EAAAA,OAAO,EAAE,KADY;AAErBC,EAAAA,QAAQ,EAAE;AAFW,CAAvB;;AAUA,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,CAACC,EAAD,EAA4D;AAAA,MAAvDC,IAAuD,uEAAhD,GAAgD;AAAA,MAA3CC,OAA2C,uEAAjCN,cAAiC;AAAA,MAAjBO,YAAiB;AACjF,MAAMC,SAAS,GAAG,wBAASJ,EAAT,EAAaC,IAAb,EAAmBC,OAAnB,CAAlB;AAEA,SAAO,wBAAYE,SAAZ,EAAuBD,YAAvB,CAAP;AACD,CAJD;;eAMeJ,c","sourcesContent":["import { useCallback } from 'react';\nimport throttle from 'lodash.throttle';\n\nconst defaultOptions = {\n leading: false,\n trailing: true,\n};\n\n/**\n * Accepts a function and returns a new throttled yet memoized version of that same function that waits the defined time\n * before allowing the next execution.\n * If time is not defined, its default value will be 100ms.\n */\nconst useThrottledFn = (fn, wait = 100, options = defaultOptions, dependencies) => {\n const throttled = throttle(fn, wait, options);\n\n return useCallback(throttled, dependencies);\n};\n\nexport default useThrottledFn;\n"],"file":"useThrottledFn.js"}
\No newline at end of file