import { useCallback, useEffect, useRef } from 'react';
/**
 * @see https://reactjs.org/docs/hooks-faq.html#what-can-i-do-if-my-effect-dependencies-change-too-often
 */
function useLatestFunc(fn) {
  var ref = useRef(fn);
  useEffect(function () {
    ref.current = fn;
  });
  var callbackFn = useCallback(function () {
    ref.current.apply(ref, arguments);
  }, []);

  // @ts-expect-error
  return fn ? callbackFn : fn;
}
export default useLatestFunc;