UNPKG

@etsoo/react

Version:

TypeScript ReactJs UI Independent Framework

23 lines (22 loc) 553 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, milliseconds) => { // 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 }; };