UNPKG

@thibault.sh/hooks

Version:

A comprehensive collection of React hooks for browser storage, UI interactions, and more

2 lines 613 B
'use strict';var react=require('react');var i=(t,e)=>{let n=new Date().getTime(),r=t-n,[s,a]=react.useState(r),o=react.useRef(null);return react.useEffect(()=>{let u=()=>{a(t-new Date().getTime());};return u(),o.current=setInterval(u,e),()=>{o.current&&clearInterval(o.current);}},[t,e]),m(s)},m=t=>{let e=Math.floor(t/864e5),n=Math.floor(t%(1e3*60*60*24)/(1e3*60*60)),r=Math.floor(t%(1e3*60*60)/(1e3*60)),s=Math.floor(t%(1e3*60)/1e3);return e<0?[0,0,0,0]:n<0?[0,0,0,0]:r<0?[0,0,0,0]:s<0?[0,0,0,0]:[e,n,r,s]},h=i;module.exports=h;//# sourceMappingURL=useCountdown.cjs.map //# sourceMappingURL=useCountdown.cjs.map