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();
         
Summer Sale 2025
SUMMER SALE2025
Use coupon code PRSM25 at checkout to get 50% OFF everything in PrimeStore and PrimeBlocks.
Learn More