UNPKG

@react-hook/timeout

Version:

A React hook that executes a callback after a timeout ms have been exceeded and the timeout has been started

3 lines (2 loc) 439 B
import{useState as r,useCallback as t,useEffect as o}from"react";import e from"@react-hook/latest";var i=function(t){void 0===t&&(t=0);var[o,e]=r(0),[i,u]=n(()=>e(1),t);return[o,i,u]},n=function(i,n){function u(){a&&clearTimeout(a)}void 0===n&&(n=0);var[a,c]=r(),m=e(i);return o(()=>u,[a,n]),[t(()=>c(setTimeout(m.current,n)),[n,m]),t(()=>c(void 0),[])]};export{i as useTimeout,n as useTimeoutCallback}; //# sourceMappingURL=index.mjs.map