UNPKG

@guruhotel/aura-hooks

Version:

🪝 Hooks library designed by the Guruhotel team for Aura UI

1 lines 352 B
import{useEffect as r,useRef as t,useState as e}from"react";export function useInterval(n,c){const[o,u]=e(!1),a=t(),i=t();r((()=>{i.current=n}),[n]);const s=()=>{u((r=>(r||a.current||(a.current=window.setInterval(i.current,c)),!0)))},l=()=>{u(!1),window.clearInterval(a.current),a.current=void 0};return{start:s,stop:l,toggle:()=>{o?l():s()},active:o}}