SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

trackHostNode

The insert/remove lifecycle bookkeeping a mixin repeats on its own before it can read or write anything on its own host element from outside its render callback.

tsx
import { trackHostNode } from "@sdxc/ui/mixins";

Usage

Caches the DOM node behind a mixin's own host element for as long as it stays mounted, since no host node exists while setup runs; insert/remove keep the returned getter's node current, or undefined while unmounted.

Signature

typescript
trackHostNode<node extends EventTarget = Element>(handle: MixinHandle<node>): () => node | undefined

Returns a getter returning the currently mounted host node, or undefined while unmounted.

Parameters

ParameterTypeDefaultRequiredDescription
handleMixinHandle<node>—YesMixin handle to track the host node of.

Examples

tsx
export const example = createMixin<HTMLElement>((handle) => {
	let hostNode = trackHostNode(handle);

	handle.queueTask(() => {
		addEventListeners(document, handle.signal, {
			keydown() {
				let node = hostNode();
				if (node === undefined) return;
				// ...
			},
		});
	});

	return () => {};
});
@sdxc/ui

Can’t find it? Contact us