File: usemouse.md | Updated: 11/15/2025
Introducing PrimeReact v11 Alpha 🥁Learn More
SearchK
10.9.7
HOOK
API
Tracks mouse position on an element or document body.
Import#
import { useMouse } from 'primereact/hooks';
Copy
Element#
Hover the mouse over the element to track the mouse position.
X: 0Y: 0
const { ref, x, y } = useMouse();
Copy
Reset#
The reset callback is provided to clear the tracked mouse position.
X: 0Y: 0
const { ref, x, y } = useMouse();
Copy
Document#
When ref is not used, the document is used as the target.
X: 0Y: 0
const { x, y } = useMouse();
Copy
Import
Element
Reset
Document
PrimeReact 10.9.7 by PrimeTek