useHover

Track whether an element is being hovered over with useHover.

Install:

npm i @uidotdev/usehooks

Description:

The useHover hook allows you to track whether an element is being hovered over or not. The hook returns a reference to attach to the target element and the current hovering status, enabling you to apply conditional rendering or perform any desired actions based on the hover state.

Return Value

The useHover hook returns an array with the following elements:

IndexTypeDescription
0refA ref object that can be attached to the element intended to be hovered.
1booleanA boolean value indicating whether the element is currently being hovered.

Demo:

Example:

More Hooks:

Sort: