use-hovering
TypeScript icon, indicating that this package has built-in type declarations

0.4.4 • Public • Published

use-hovering 🧞

Simple, accessible React hook for tracking hover state.

npm npm

Install

npm install use-hovering

Usage

Plain

import { useHovering } from 'use-hovering';

export const Example = () => {
  const ref = React.useRef();
  const hovering = useHovering(ref);

  return (
    <div ref={ref} tabIndex={0}>
      Hover over me!{hovering && ' Hovering!'}
    </div>
  );
};

With delay

import { useHovering } from 'use-hovering';

export const Example = () => {
  const ref = React.useRef();
  const hovering = useHovering(ref, {
    enterDelay: 250,
    exitDelay: 250,
  });

  return (
    <div ref={ref} tabIndex={0}>
      Hover over me!{hovering && ' Hovering!'}
    </div>
  );
};

Dependents (0)

Package Sidebar

Install

npm i use-hovering

Weekly Downloads

50

Version

0.4.4

License

MIT

Unpacked Size

19.5 kB

Total Files

11

Last publish

Collaborators

  • therealparmesh