UNPKG

@etsoo/react

Version:

TypeScript ReactJs UI Independent Framework

30 lines (25 loc) 559 B
import { ExtendUtils } from "@etsoo/shared"; import React from "react"; /** * For setTimeout to merge actions * @param action Action function * @param milliseconds Interval of milliseconds */ export const useTimeout = ( action: (...args: any[]) => void, milliseconds: number ) => { // Delayed const d = ExtendUtils.delayedExecutor(action, milliseconds); // Merge into the life cycle React.useEffect(() => { d.call(); return () => { d.clear(); }; }, []); // Return cancel method return { cancel: d.clear }; };