跳到主要内容

useHover

跟踪鼠标是否在元素上。

Usage

实时编辑器

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

结果
Loading...

API

useHover

Returns

boolean

Arguments

参数名描述类型默认值
targetdom对象BasicTarget<T> (必填)-

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;