useMousePosition
This hook tracks the mouse cursor position
of a target element.
Parameters
- the
ref
object of the target element (default iswindow
).
Return Values
Name | Type | Description |
---|---|---|
ref | RefObject | the target element reference. |
x | Number | the x position. |
y | Number | the y position. |
Example Usage
tsx
import { useMousePosition } from 'react-pre-hooks';
export default function Trailer() {
const { x: left, y: top } = useMousePosition();
return (
<main>
<div style={{ top, left }}></div>
</main>
);
}
import { useMousePosition } from 'react-pre-hooks';
export default function Trailer() {
const { x: left, y: top } = useMousePosition();
return (
<main>
<div style={{ top, left }}></div>
</main>
);
}