import { useRef, useEffect, useCallback } from 'react';

/*
 * Inspired by:
 *
 * - https://react.dev/learn/separating-events-from-effects#declaring-an-effect-event
 * - https://legacy.reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
 */
function useEffectEvent(callback) {
  const ref = useRef(() => {
    throw new Error('Cannot call an event handler while rendering.');
  });
  useEffect(() => {
    ref.current = callback;
  });
  return useCallback((...args) => ref.current(...args), []);
}

export { useEffectEvent };
//# sourceMappingURL=useEffectEvent.mjs.map
