|
Download react-use/docs/useMouse.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 925 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useMouse.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/docs/useMouse.md
-
curl -L -o useMouse.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useMouse.md
925 Bytes
useMouse and useMouseHovered
React sensor hooks that re-render on mouse position changes. useMouse simply tracks
mouse position; useMouseHovered allows you to specify extra options:
bound— to bind mouse coordinates within the elementwhenHovered— whether to attachmousemoveevent handler only when user hovers over the element
Usage
import {useMouse} from 'react-use';
const Demo = () => {
const ref = React.useRef(null);
const {docX, docY, posX, posY, elX, elY, elW, elH} = useMouse(ref);
return (
<div ref={ref}>
<div>Mouse position in document - x:{docX} y:{docY}</div>
<div>Mouse position in element - x:{elX} y:{elY}</div>
<div>Element position- x:{posX} y:{posY}</div>
<div>Element dimensions - {elW}x{elH}</div>
</div>
);
};
Reference
useMouse(ref);
useMouseHovered(ref, {bound: false, whenHovered: false});