Skip to content

A lightweight (508 B) package to easily track mouse position in React.js

License

Notifications You must be signed in to change notification settings

hxf31891/react-use-mouse-position

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

useMousePosition - a custom React hook

  • A lightweight (508 B) package to easily track mouse position in Reactjs
  • Very useful for tinder style cards and other draggable elements
  • v1.0.2 adds a variety of touch events, improving mobile usability

Install

npm install react-use-mouse-position

Example

import React from "react";
import { useMousePosition } from "react-use-mouse-position";

function MyApp() {
  const { mouseX, mouseY } = useMousePosition();
  console.log("mouseX:", mouseX);
}

useMousePosition returns

Name Type Default Description
mouseX num The mouses current x position
mouseY num The mouses current y position

License

Code released under the MIT license.

About

A lightweight (508 B) package to easily track mouse position in React.js

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published