use-mouse
Get mouse position relative to viewport or given element
Import
Source
Docs
Package
Usage
Mouse coordinates
{ x: 0, y: 0 }
If you do not provide ref
mouse position will be captured relative to document element:
Mouse coordinates
{ x: 0, y: 0 }
API
Hook returns 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
.