Overview
onConnect(cb) fires after the decorated element is connected to the live DOM. onDisconnect(cb) fires when it is removed. Both receive the element as the first argument.
These are element-scoped — useful when a specific node (not the whole component) needs focus, measurement, or third-party teardown.
Element directives vs component hooks
|
API
|
Scope
|
Notes
|
|---|---|---|
onConnect / onDisconnect
| Per element | Element directives on a single node in the template. |
onMount / onCleanup
| Per component | Outer-function hooks for the whole component lifetime. See /docs/lifecycle/on-mount. |
eleHook
| Full imperative | Mount + onUpdate + onCleanup when you need ongoing sync. |
Element connect / disconnect log
onConnect fires after the element is appended to the live DOM tree; onDisconnect fires just before it is removed. Both receive the element itself as the first argument.
Autofocus input
onConnect receives the element — focus an input when it mounts.