UNPKG

ahooks

Version:
23 lines (22 loc) 566 B
import { __awaiter } from "tslib"; import { useRef, useCallback } from 'react'; function useLockFn(fn) { const lockRef = useRef(false); return useCallback((...args) => __awaiter(this, void 0, void 0, function* () { if (lockRef.current) { return; } lockRef.current = true; try { const ret = yield fn(...args); return ret; } catch (e) { throw e; } finally { lockRef.current = false; } }), [fn]); } export default useLockFn;