useMouse

About

Description

Mouse position hook for React.


Return value

useMouse returns a single object containing the mouse position.

Returned object attributesTypeDescription
xintX position of mouse
yintY position of mouse

Examples

Basic Usage

import { useMouse } from "rooks";

export default function App() {
  const { x, y } = useMouse();
  return (
    <>
      <p> Move mouse here to see changes to position </p>
      <p>X position is {x || "null"}</p>
      <p>X position is {y || "null"}</p>
    </>
  );
}


Join the community!

Join our discord server! You can click the floating discord icon at the bottom right of the screen and chat with us!

Powered by vercel