UNPKG

@gdjiami/hooks

Version:

react hooks for mygzb.com

25 lines (20 loc) 504 B
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, args); }, args); } export { useOnUpdate };