Skip to main content

useHover

Detect if mouse is over given element.

Usage

Live Editor
function Demo() {
  const ref = useRef<HTMLDivElement>(null);
  const hovered = useHover(ref);
  return <div ref={ref}> {hovered ? "true" : "false"}</div>;
};

Result
Loading...

API

useHover

Returns

boolean

Arguments

ArgumentDescriptionTypeDefaultValue
targetdom elementBasicTarget<T> (Required)-

BasicTarget

export type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>;

TargetValue

type TargetValue<T> = T | undefined | null;

TargetType

type TargetType = HTMLElement | Element | Window | Document | EventTarget;