@guruhotel/aura-hooks
Version:
🪝 Hooks library designed by the Guruhotel team for Aura UI
1 lines • 477 B
JavaScript
import{useState as e,useEffect as t,useRef as n}from"react";const r={events:["keypress","mousemove","touchmove","click","scroll"],initialState:!0};export function useIdle(o,c){const{events:i,initialState:s}={...r,...c},[u,m]=e(s),a=n();return t((()=>{const e=()=>{m(!1),a.current&&window.clearTimeout(a.current),a.current=window.setTimeout((()=>{m(!0)}),o)};return i.forEach((t=>document.addEventListener(t,e))),()=>{i.forEach((t=>document.removeEventListener(t,e)))}}),[o]),u}