useHoverui-interaction
useHover
NewSSR SAFETracks hover state of a target element with optional delay.
$ pnpm dlx shadcn@latest add @byphongphan/use-hoverRequires
@byphongphan in components.jsonuse-hover.tsx
Loading preview...
Installation
$ pnpm dlx shadcn@latest add @byphongphan/use-hoverRequires
@byphongphan in components.jsonUsage
Props & Parameters
| Param | Type | Default | Description |
|---|---|---|---|
options.enterDelay | number | 0 | Delay in milliseconds before triggering hover on state (true). |
options.leaveDelay | number | 0 | Delay in milliseconds before triggering hover off state (false). |
options.onEnter | (event: PointerEvent) => void | — | Callback invoked when the pointer enters the element. |
options.onLeave | (event: PointerEvent) => void | — | Callback invoked when the pointer leaves the element. |
options.enabled | boolean | true | Whether the hover event listener is active. |
options.ref | RefObject<T | null> | — | Optional external ref to attach to instead of the returned ref. |
Returns
| Return Value | Type | Description |
|---|---|---|
[0] (ref) | RefObject<T | null> | Ref object to attach to the target DOM element. |
[1] (isHovered) | boolean | Current hover status of the target element. |