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

1.0.2 • Public • Published

useHover

A React hook that determines if the mouse is hovering an element.

license npm latest package npm downloads types

npm i @utilityjs/use-hover | yarn add @utilityjs/use-hover

Usage

const App: React.FC = () => {
  const { isHovered, registerRef } = useHover();

  return (
    <div className="app">
      <div ref={registerRef}>
        {`The current div is ${isHovered ? `hovered` : `unhovered`}`}
      </div>
    </div>
  );
};

API

useHover()

declare const useHover: () => {
  isHovered: boolean;
  setIsHovered: React.Dispatch<React.SetStateAction<boolean>>;
  registerRef: <T extends HTMLElement>(node: T | null) => void;
};

Package Sidebar

Install

npm i @utilityjs/use-hover

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

5.7 kB

Total Files

8

Last publish

Collaborators

  • mimshins