Loading homepage
Implement a React hook that subscribes to a browser event on a chosen EventTarget and keeps the subscription in sync with the current handler and target.
The JavaScript and TypeScript variants share the same contract. Tests render real React components and exercise updates and lifecycle cleanup.
Input: useEventListener("resize", onResize) Output: Subscribes on window while mounted.
Input: useEventListener("click", onClick, button, true) Output: Subscribes on button during the capture phase.
Input: Rerender with target = null Output: Removes the prior listener and disables events until another target is supplied.
Examples describe the current return value after the corresponding React render or event.