vue-hooks-plus
Version:
Vue hooks library
23 lines (22 loc) • 613 B
JavaScript
import { getTargetElement } from "../utils/domTarget";
import useDeepCompareEffectWithTarget from "../utils/useDeepCompareWithTarget";
const useMutationObserver = (callback, target, options = {}) => {
useDeepCompareEffectWithTarget(
() => {
const element = getTargetElement(target);
if (!element) {
return;
}
const observer = new MutationObserver(callback);
observer.observe(element, options);
return () => {
observer == null ? void 0 : observer.disconnect();
};
},
[options],
target
);
};
export {
useMutationObserver as default
};