fn
onElementRemoval
v0.0.14testeddemoFire a callback when the target element — or any ancestor containing it — is
removed from the DOM. Backed by a single childList/subtree MutationObserver on the
element's owning document, so it also catches removal of a parent further up the tree.
Examples
ts
const el = useTemplateRef<HTMLElement>('el');
onElementRemoval(el, () => console.log('gone'));ts
const stop = onElementRemoval(el, (records) => report(records), { flush: 'post' });Demo
Loading demo…
Signature
ts
export function onElementRemoval(
target: MaybeComputedElementRef,
callback: OnElementRemovalCallback,
options: OnElementRemovalOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
target | MaybeComputedElementRef | Element (or ref/getter) to watch for removal |
callback | OnElementRemovalCallback | Invoked with the mutation records that removed the element |
options? | OnElementRemovalOptions | window, document, and watcher flush timing |
Returns
OnElementRemovalReturnStop handle that tears down the watcher and observer