React hook for mouse position, movement and buttion states
npm install react-hook-mouseA React hook to access data from mouse events.
Using npm:
``sh`
npm install --save react-hook-mouse
Using yarn:
`sh`
yarn add react-hook-mouse
`jsx
import React from 'react'
import useMouse from 'react-hook-mouse'
const displayCoordinates = ({x, y}) => ${x} : ${y}
const displayFlag = flag => flag ? 'Yes' : 'No'
const ComponentWithMouse = () => {
const mouse = useMouse()
return (
Caveats
Data in
mouse.keyboard is always read from a MouseEvent` and therefore it will only get updated on mouse events, not when the keys are actually pressed on the keyboard.Contributions are welcome. File bug reports, create pull requests, feel free to reach out at tothab@gmail.com.
LGPL-3.0