addWindowListener
Commons
stable
Register an event listener on window and push its cleanup function into an array collected on unmount. Returns a standalone remove callback for manual teardown.
API
Signature
Full TypeScript signature sourced from the util file.
API
Parameters
Input parameters accepted by this util.
- eventrequiredstring
- The DOM event type to listen for, e.g. "resize" or "scroll".
- listenerrequiredEventListenerOrEventListenerObject
- The event handler callback or object with a handleEvent method.
- onUnmountedCleanupFnsany[]
- Optional array that collects cleanup functions automatically called when the component unmounts.
API
Return value
The value returned by this util.
- A function that removes the listener from window and splices its entry out of onUnmountedCleanupFns.
Usage
Examples
Ready-to-paste usage snippets.
Listen to resize with automatic cleanup