Skip to content

useWindowEventListener

useWindowEventListener<K>(type, handler, options?): void

Defined in: renderer/hooks/useWindowState.ts:73

Attach an event listener to the window’s document that is automatically removed when the window closes. Wraps addEventListener(type, handler, { signal }) in a useEffect so the handler can be an inline arrow.

Re-attaches when type changes. The handler is read through a ref so it can change identity without re-subscribing.

K extends keyof DocumentEventMap

K

(event) => void

Omit<AddEventListenerOptions, "signal">

void

useWindowEventListener("keydown", (e) => {
if (e.key === "Escape") close();
});