useMousePosition - a custom React hook
- A lightweight (508 B) package to easily track mouse position in React.js
- Very useful for tinder style cards and other dragable elements
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.