import '../../../../preact/compat/dist/compat.module.mjs';
import useEnhancedEffect from '../useEnhancedEffect/useEnhancedEffect.mjs';
import { useRef as _ } from '../../../../preact/hooks/dist/hooks.module.mjs';

/**
 * Inspired by https://github.com/facebook/react/issues/14099#issuecomment-440013892
 * See RFC in https://github.com/reactjs/rfcs/pull/220
 */

function useEventCallback(fn) {
  const ref = _(fn);
  useEnhancedEffect(() => {
    ref.current = fn;
  });
  return _((...args) =>
  // @ts-expect-error hide `this`
  (0, ref.current)(...args)).current;
}

export { useEventCallback as default };
//# sourceMappingURL=useEventCallback.mjs.map
