fn
useMutationObserver
v0.0.15testeddemoWatch for changes to the DOM tree via `MutationObserver`. Accepts a single target, an array of targets, or a getter returning either.
Examples
ts
useMutationObserver(el, (records) => {
console.log(records);
}, { attributes: true });ts
const { pause, resume } = useMutationObserver([elA, elB], onMutate, { childList: true });Demo
Loading demo…
Signature
ts
export function useMutationObserver(
target: MaybeComputedElementRef | MaybeComputedElementRef[] | MaybeRefOrGetter<MaybeElement[]>,
callback: MutationCallback,
options: UseMutationObserverOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
target | any | Element(s) to observe |
callback | MutationCallback | Invoked with the mutation records |
options? | UseMutationObserverOptions | Observer options (childList, attributes, …) |
Returns
UseMutationObserverReturn`isSupported`, `isActive`, `pause`, `resume`, `stop`, and `takeRecords`