web-api-hooks
Version:
Essential set of React Hooks for convenient Web API consumption.
20 lines (19 loc) • 596 B
TypeScript
/**
* Tracks hover state of an element.
*
* @param {boolean} disallowTouch Determines whether touch gestures should be ignored.
* @returns Whether the element is hovered, and props to be spread over the element under observation.
*
* @example
* function Component() {
* const [isHovered, bindHover] = useHover();
* // ...
* return <ElementToObserve {...bindHover} />;
* }
*/
export default function useHover(disallowTouch?: boolean): [boolean, Readonly<{
onMouseEnter: () => void;
onMouseLeave: () => void;
onTouchStart: () => void;
onTouchEnd: () => void;
}>];