useHover

React UI sensor hooks that track if some element is being hovered by a mouse.

API is consistent with ahooks.

Examples

Basic Uagge

isHovering: false
Basic usageUse ref to set elements that need listen dom.

Pass in DOM element

isHovering: false
Pass in DOM elementPass in a function that returns the DOM element.

API

const isHovering = useHover(target, {
  onEnter,
  onLeave,
});

Params

PropertyDescriptionTypeDefault
targetDOM element or Ref Object(() => HTMLElement) | HTMLElement | React.RefObject-
onEnterListen to hover()=>void-
onLeaveListening leave hover()=>void-

Result

PropertyDescriptionType
isHoveringDetermine whether the mouse element is in the hover elementboolean

最近更新:7/29/2021, 3:48:51 AM