use-mouse-move
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

useMouseMove Tweet version minzipped size downloads build

Listen to mouse move events with a React hook.

Install

  • npm install use-mouse-move or
  • yarn add use-mouse-move

Use

import useMouseMove from 'use-mouse-move';

function App() {
  const [x, y] = useMouseMove();
  return (
    <p>
      Your mouse coordinates are {x}, {y}.
    </p>
  );
}

Variants

The useMouseMove hook accepts one parameter -- a MouseMoveVariant enum that you can import from the use-mouse-move package. These variants coincide with the different x/y coordinates emit by mouse move events.

import useMouseMove, { MouseMoveVariant } from 'use-mouse-move';
useMouseMove(MouseMoveVariant.Default);
  • MouseMoveVariant.Default: x and y (default if no variant is specified)
  • MouseMoveVariant.Client: clientX and clientY
  • MouseMoveVariant.Movement: movementX and movementY (relative movement)
  • MouseMoveVariant.Offset: offsetX and offsetY
  • MouseMoveVariant.Page: pageX and pageY
  • MouseMoveVariant.Screen: screenX and screenY

Sponsor 💗

If you are a fan of this project, you may become a sponsor via GitHub's Sponsors Program.

Readme

Keywords

none

Package Sidebar

Install

npm i use-mouse-move

Weekly Downloads

3

Version

1.0.1

License

MIT

Unpacked Size

12.1 kB

Total Files

6

Last publish

Collaborators

  • charlesstover