Loading homepage
Create a React hook that tracks whether the pointer is hovering over an element. Use a callback ref so that attaching, replacing, and detaching the element all work correctly.
The JavaScript and TypeScript variants share the same contract. Tests render real React components and exercise updates and lifecycle cleanup.
Input: const [ref, hovered] = useHover(); attach ref to a button Output: hovered is false until the button receives mouseenter.
Input: mouseenter followed by mouseleave Output: hovered changes from true to false.
Input: Replace the referenced node while hovered Output: The replacement begins unhovered and the old node no longer affects the hook.
Examples describe the current return value after the corresponding React render or event.