UNPKG

@guruhotel/aura-hooks

Version:

🪝 Hooks library designed by the Guruhotel team for Aura UI

1 lines 382 B
import{useEffect as e,useState as r,useRef as n}from"react";export function useDebouncedValue(t,u,c={leading:!1}){const[o,i]=r(t),d=n(!1),a=n(void 0),l=n(!1),m=()=>window.clearTimeout(a.current);return e((()=>{d.current&&(!l.current&&c.leading?(l.current=!0,i(t)):(m(),a.current=window.setTimeout((()=>{l.current=!1,i(t)}),u)))}),[t,c.leading,u]),e((()=>(d.current=!0,m)),[]),[o,m]}