useHover
A hook that tracks whether the element is being hovered.
Overview
A hook that tracks whether the element is being hovered.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useHover.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useHover.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useHover.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useHover.jsonA 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
| Property | Description | Type | Default |
|---|---|---|---|
| target | DOM element or ref | () => Element | Element | MutableRefObject<Element> | - |
| options | More config | Options | - |
Options
| Property | Description | Type | Default |
|---|---|---|---|
| onEnter | Callback to be executed on mouse hover | () => void | - |
| onLeave | Callback to be executed on mouse leave | () => void | - |
| onChange | Callback to be executed on hover change | (isHovering: boolean) => void | - |
Result
| Property | Description | Type |
|---|---|---|
| isHovering | Whether the element is being hovered | boolean |