// Copyright 1999-2024. Plesk International GmbH. All rights reserved.

import { useEffect, useRef } from 'react';
export const useResizeObserver = _ref => {
  let {
    ref,
    onResize
  } = _ref;
  const onResizeRef = useRef(undefined);
  onResizeRef.current = onResize;
  useEffect(() => {
    if (!ref.current) return undefined;
    if (typeof window === 'undefined' || !('ResizeObserver' in window)) return undefined;
    const observer = new ResizeObserver(() => {
      onResizeRef.current?.();
    });
    observer.observe(ref.current);
    return () => {
      observer.disconnect();
    };
  }, [ref]);
};