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.
Type Parameters
Section titled “Type Parameters”K extends keyof DocumentEventMap
Parameters
Section titled “Parameters”K
handler
Section titled “handler”(event) => void
options?
Section titled “options?”Omit<AddEventListenerOptions, "signal">
Returns
Section titled “Returns”void
Example
Section titled “Example”useWindowEventListener("keydown", (e) => { if (e.key === "Escape") close();});