UNPKG

@etsoo/react

Version:

TypeScript ReactJs UI Independent Framework

30 lines (29 loc) 865 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useTimeout = void 0; const shared_1 = require("@etsoo/shared"); const react_1 = __importDefault(require("react")); /** * For setTimeout to merge actions * @param action Action function * @param milliseconds Interval of milliseconds */ const useTimeout = (action, milliseconds) => { // Delayed const d = shared_1.ExtendUtils.delayedExecutor(action, milliseconds); // Merge into the life cycle react_1.default.useEffect(() => { d.call(); return () => { d.clear(); }; }, []); // Return cancel method return { cancel: d.clear }; }; exports.useTimeout = useTimeout;