Docs
useHover
Track whether an element is being hovered over with useHover.
Loading...
Installation
pnpm dlx shadcn@latest add https://usekit.kiron.dev/k/use-hover
Usage
"use client"
import { useHover } from "@/hooks/use-hover"
export function Component() {
const [hoverRef, hovering] = useHover()
return (
<div
ref={hoverRef}
style={{
width: 200,
height: 200,
backgroundColor: hovering ? "lightblue" : "white",
}}
>
{hovering ? "Hovering!" : "Hover over me"}
</div>
)
}
API Reference
Return Values
Index | Type | Description |
---|---|---|
0 | ref | A ref object that can be attached to the element intended to be hovered. |
1 | boolean | A boolean value indicating whether the element is currently being hovered. |