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

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

Paramètres d'entrée acceptés par cet util.

event
requis
string
The DOM event type to listen for, e.g. "resize" or "scroll".
listener
requis
EventListenerOrEventListenerObject
The event handler callback or object with a handleEvent method.
onUnmountedCleanupFns
any
[]
Optional array that collects cleanup functions automatically called when the component unmounts.

API

Valeur de retour

La valeur retournée par cet util.

A function that removes the listener from window and splices its entry out of onUnmountedCleanupFns.

Usage

Exemples

Extraits de code prêts à coller.

Listen to resize with automatic cleanup

typescript