Overview
onWindow(event, fn) attaches a bubble-phase listener on window, tied to the component lifetime.
onWindowCapture(event, fn) uses the capture phase — required for non-bubbling events like scroll, or when you must run before target handlers.
Both accept any WindowEventMap name plus synthetic 'wheelUp' / 'wheelDown'. Handlers may return cleanup. Listeners are removed on unmount. SSR no-op.
Bubble vs capture
|
API
|
Phase
|
Use when
|
|---|---|---|
onWindow
| bubble | Most events (keydown, resize, online, …). |
onWindowCapture
| capture | scroll / focus / blur; intercept before target. |
onWindow + onWindowCapture
Bubble Escape and capture-phase clicks. Listeners tear down with the component.