Simple, accessible React hook for tracking hover state.
npm install use-hovering
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>
);
};
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>
);
};