Hook Master 🚀

useIsHovered

Detects if given element is hovered

Usage

import { useIsHovered } from 'hook-master-react';
 
function Demo() {
  const { hovered, ref } = useIsHovered();
  return (
    <div ref={ref}>
      {hovered ? 'I am hovered' : 'Hover on me'}
    </div>
  );
}

Definition

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

On this page