# 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 — a document-level listener, an observer callback, a queued task — since the host node doesn't exist yet while a mixin's setup function runs, and stops existing again once the host unmounts.

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

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

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

Returns: A getter returning the currently mounted host node, or `undefined` while unmounted.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `handle` | `MixinHandle<node>` | Mixin handle to track the host node of. |

## Examples

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

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

	return () => {};
});
```
