use-hover

Detects if given element is hovered

Import

Usage

Put mouse over me please

import { useHover } from '@mantine/hooks';

function Demo() {
  const { hovered, ref } = useHover();
  return (
    <div ref={ref}>
      {hovered ? 'I am hovered' : 'Put mouse over me please'}
    </div>
  );
}

Definition

function useHover<T extends HTMLElement = HTMLDivElement>(): {
  ref: React.RefObject<T>;
  hovered: boolean;
};