
Security News
Insecure Agents Podcast: Certified Patches, Supply Chain Security, and AI Agents
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.
@react-hook/mouse-position
Advanced tools
A React hook for tracking the position of the mouse as it moves around an element.
npm i @react-hook/mouse-position
A React hook for tracking the position of the mouse as it moves around an element. This
hook also provides an interop between touch and desktop devices and will treat
ontouch events the same as onmouse ones.
import useMousePosition from '@react-hook/mouse-position'
const Component = props => {
const [mousePosition, ref] = useMousePosition(
0, // enterDelay
0, // leaveDelay
30 // fps
)
return (
<div ref={ref}>
Hover me and see where I am relative to the element:
<br />
x: ${mousePosition.x}
y: ${mousePosition.y}
</div>
)
}
useMousePosition(enterDelay?: number, leaveDelay?: number, fps?: number)| Argument | Type | Default | Description |
|---|---|---|---|
| enterDelay | number | 0 | The amount of time in ms to wait after an initial action before setting mousemove events to state |
| leaveDelay | number | 0 | The amount of time in ms to wait after a final action before setting mouseleave events to state |
| fps | number | 30 | The rate in frames-per-second that the state should update |
[state: MousePosition, ref: (element: HTMLElement | null) => void]| Variable | Description |
|---|---|
state | The mouse position data for the ref'd element |
ref | The callback ref you must provide to the element you want to track mouse data position of |
| Key | Type | Default | Description |
|---|---|---|---|
| x | number | null | Mouse position relative to the left edge of the element, null if mouse is not over the element |
| y | number | null | Mouse position relative to the top edge of the element, null if mouse is not over the element |
| pageX | number | null | Mouse position relative to the left edge of the document, null if mouse is not over the element |
| pageY | number | null | Mouse position relative to the top edge of the document, null if mouse is not over the element |
| clientX | number | null | Mouse position relative to the left edge of the client, null if mouse is not over the element |
| clientY | number | null | Mouse position relative to the top edge of the client, null if mouse is not over the element |
| screenX | number | null | Mouse position relative to the left edge of the screen, null if mouse is not over the element |
| screenY | number | null | Mouse position relative to the top edge of the screen, null if mouse is not over the element |
| elementWidth | number | null | DOMRect.width of the element, null if mouse is not over the element |
| elementHeight | number | null | DOMRect.height of the element, null if mouse is not over the element |
| isOver | boolean | false | true if the mouse is currently hovering over the element |
| isDown | boolean | false | true if the mouse is currently hovering over the element AND is down |
| isTouch | boolean | false | true if the the last event was triggered by a touch event |
MIT
FAQs
A React hook for tracking the position, hover, and down state of the mouse as it interacts with an element with interop between touch and mouse devices.
We found that @react-hook/mouse-position demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.

Security News
The planned feature introduces a review step before releases go live, following the Shai-Hulud attacks and a rocky migration off classic tokens that disrupted maintainer workflows.