raddix

useHover

Detects if given element is hovered.

Instalación

npm i @raddix/use-hover

Uso

import { useRef } from 'react';
import { useHover } from '@raddix/use-hover';
export const App = () => {
const boxRef = useRef<HTMLDivElement>(null);
const isHovered = useHover(divRef);
return (
<div ref={boxRef}>
{isHovered ? '😁' : '☹️'}
</div>
);
};

API

Parameters

NameDescriptionRequiredType
refDOM element being referenced.YesRefObject