import { useEffect } from 'react';
import { useEffectEvent } from './useEffectEvent.mjs';

function useResizeObserver(ref, callback, box = 'border-box') {
  const handleCallback = useEffectEvent(callback);
  useEffect(() => {
    if (ref.current != null) {
      const resizeObserver = new ResizeObserver(([entry]) => {
        handleCallback(entry);
      });
      resizeObserver.observe(ref.current, {
        box
      });
      return () => {
        resizeObserver.disconnect();
      };
    }
    return () => {};
  }, [handleCallback, ref, box]);
}

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