Custom hook that adds an event listener to a target element or window.
This hook takes an event name and a handler function, and optionally a ref to a target element. It ensures the event listener is properly added and removed when dependencies change.
The type of the event name.
Custom hook that adds an event listener to a target element or window.
This hook takes an event name and a handler function, and optionally a ref to a target element. It ensures the event listener is properly added and removed when dependencies change.
The type of the event name.
The type of the target element.
Custom hook that adds an event listener to a target element or window.
This hook takes an event name, a handler function, and optionally a ref to a target element. It ensures the event listener is properly added and removed when dependencies change.
Template: KW
The type of the window event name.
Template: KH
The type of the HTMLElement event name.
Template: T
The type of the target element, or void if no element is provided.
Param: eventName
The name of the event to listen for.
Param: handler
The function to handle the event.
Param: element
Optional ref object of the target element.
Example