@react-hook/throttle
Version:
A React hook for throttling setState and other callbacks
3 lines (2 loc) • 719 B
JavaScript
function r(r,e,o){function i(){p.current=0,l()}void 0===e&&(e=30),void 0===o&&(o=0);var a=c(r),m=1e3/e,p=t(0),v=t(),l=()=>v.current&&clearTimeout(v.current),d=[e,o,a];return n(()=>i,d),u((function(){var r=arguments,e=f(),t=()=>{p.current=e,l(),a.current.apply(null,r)},n=p.current;if(o&&0===n)return t();if(e-n>m){if(n>0)return t();p.current=e}l(),v.current=setTimeout(()=>{t(),p.current=0},m)}),d)}function e(e,t,n){var u=o(e);return[u[0],r(u[1],t,n)]}import{useRef as t,useEffect as n,useCallback as u,useState as o}from"react";import c from"@react-hook/latest";var i="undefined"!=typeof performance?performance:Date,f=()=>i.now();export{e as useThrottle,r as useThrottleCallback};
//# sourceMappingURL=index.mjs.map