UNPKG

@gdjiami/hooks

Version:

react hooks for mygzb.com

18 lines (17 loc) 593 B
import { __read, __spread } from "tslib"; import { useEffect, useRef } from 'react'; import useRefProps from './useRefProps'; function useOnUpdate(fn, args, skipOnMount) { if (args === void 0) { args = []; } if (skipOnMount === void 0) { skipOnMount = true; } var fnRef = useRefProps(fn); var mountedRef = useRef(false); useEffect(function () { if (!mountedRef.current && skipOnMount) { mountedRef.current = true; return; } fnRef.current.apply(fnRef, __spread(args)); }, args); } export { useOnUpdate };