use-hover

Detects if 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.MutableRefObject<T>;
  hovered: boolean;
};