mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-27 22:30:56 +00:00
22 lines
638 B
JavaScript
22 lines
638 B
JavaScript
'use client';
|
|
import { useRef, useEffect } from 'react';
|
|
|
|
function useMutationObserver(callback, options, target) {
|
|
const observer = useRef(null);
|
|
const ref = useRef(null);
|
|
useEffect(() => {
|
|
const targetElement = typeof target === "function" ? target() : target;
|
|
if (targetElement || ref.current) {
|
|
observer.current = new MutationObserver(callback);
|
|
observer.current.observe(targetElement || ref.current, options);
|
|
}
|
|
return () => {
|
|
observer.current?.disconnect();
|
|
};
|
|
}, [callback, options]);
|
|
return ref;
|
|
}
|
|
|
|
export { useMutationObserver };
|
|
//# sourceMappingURL=use-mutation-observer.mjs.map
|