use-mouse
Tracks mouse position over the viewport or given element
Import
Source
Docs
Package
Usage
Mouse coordinates { x: 0, y: 0 }
If you do not provide ref
, mouse position is tracked relative to the document element:
Mouse coordinates { x: 0, y: 0 }
API
Set resetOnExit
option to reset mouse position to 0, 0
when mouse leaves the element:
The hook returns an object with ref
and x
, y
mouse coordinates:
On the first render (as well as during SSR), both x
and y
values are equal to 0
.