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

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.