@reactdev/react-use-hover
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

react-use-hover

Detect whether the mouse is hovering an element. The hook returns a ref and a boolean value indicating whether the element with that ref is currently being hovered. Just add the returned ref to any element whose hover state you want to monitor. One potential bug with this method: If you have logic that changes the element that hoverRef is added to then your event listeners will not necessarily get applied to the new element. If you need this functionality then use this alternate version that utilizes a callback ref.

Usage

npm i @reactdev/react-use-hover
import useHover from "@reactdev/react-use-hover";
function App() {
  const [hoverRef, isHovered] = useHover();

  return <div ref={hoverRef}>{isHovered ? "😁" : "☹️"}</div>;
}

/@reactdev/react-use-hover/

    Package Sidebar

    Install

    npm i @reactdev/react-use-hover

    Weekly Downloads

    1

    Version

    1.0.0

    License

    ISC

    Unpacked Size

    16 kB

    Total Files

    8

    Last publish

    Collaborators

    • sonal_sithara