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
参数名 | 描述 | 类型 | 默认值 |
---|---|---|---|
target | dom对象 | 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;