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
Set resetOnExit option to reset mouse position to 0, 0 when mouse leaves the element
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.