@thibault.sh/hooks
Version:
A comprehensive collection of React hooks for browser storage, UI interactions, and more
2 lines • 387 B
JavaScript
import {useState,useRef,useEffect}from'react';function f(t,e){let[u,n]=useState(t),o=useRef(Date.now());return useEffect(()=>{let r=Date.now(),s=r-o.current;if(s>=e)n(t),o.current=r;else {let c=setTimeout(()=>{n(t),o.current=Date.now();},e-s);return ()=>clearTimeout(c)}},[t,e]),u}export{f as useThrottle};//# sourceMappingURL=useThrottle.mjs.map
//# sourceMappingURL=useThrottle.mjs.map