useMouse

Tracks mouse position on an element or document body.


import { useMouse } from 'primereact/hooks';
         

Hover the mouse over the element to track the mouse position.

X: 0Y: 0

const { ref, x, y } = useMouse();
         

The reset callback is provided to clear the tracked mouse position.

X: 0Y: 0

const { ref, x, y } = useMouse();
         

When ref is not used, the document is used as the target.

X: 0Y: 0

const { x, y } = useMouse();