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

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