shadcn-ahooks

useHover

A hook that tracks whether the element is being hovered.

Overview

A hook that tracks whether the element is being hovered.

Documentation and Examples

Installation

Open in
pnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useHover.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useHover.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useHover.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useHover.json

A hook that tracks whether the element is being hovered.

Examples

Default usage

Pass in DOM element

API

const isHovering = useHover(
  target,
  {
   onEnter,
   onLeave,
   onChange
  }
);

Params

PropertyDescriptionTypeDefault
targetDOM element or ref() => Element | Element | MutableRefObject<Element>-
optionsMore configOptions-

Options

PropertyDescriptionTypeDefault
onEnterCallback to be executed on mouse hover() => void-
onLeaveCallback to be executed on mouse leave() => void-
onChangeCallback to be executed on hover change(isHovering: boolean) => void-

Result

PropertyDescriptionType
isHoveringWhether the element is being hoveredboolean

On this page