Skip to content
👇Bread n butter utility for component-tied mouse/touch gestures in React
TypeScript JavaScript CSS
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docusaurus 7.0.1 Jan 31, 2020
src fix: Adds both mouse and touch handlers for drag. Feb 7, 2020
test fix: velocity set to [0,0] when scroll / move / wheel movement is over Jan 13, 2020
.eslintignore Added linting + bumped React min version to 16.8 to support hooks Apr 10, 2019
.eslintrc.js lint: linting Nov 21, 2019
.gitignore
.npmignore gif Mar 24, 2018
.travis.yml TS rewrite May 27, 2019
CHANGELOG.md 7.0.4 Feb 7, 2020
LICENSE first draft Mar 23, 2018
README.md [docs] Remove beta tags Jan 26, 2020
package.json deps: package update Feb 7, 2020
tsconfig.json lint: linting Nov 21, 2019
yarn.lock deps: package update Feb 7, 2020

README.md

react-use-gesture

npm (tag) npm bundle size NPM Travis (.org) branch

React-use-gesture is a hook that lets you bind richer mouse and touch events to any component or view. With the data you receive, it becomes trivial to set up gestures, and often takes no more than a few lines of code.

You can use it stand-alone, but to make the most of it you should combine it with an animation library like react-spring, though you can most certainly use any other.

The demos are real click them!

Installation

#Yarn
yarn add react-use-gesture

#NPM
npm install --save react-use-gesture

Full documentation website

Simple example

import { useSpring, animated } from 'react-spring'
import { useDrag } from 'react-use-gesture'

function PullRelease() {
  const [{ x, y }, set] = useSpring(() => ({ x: 0, y: 0 }))

  // Set the drag hook and define component movement based on gesture data
  const bind = useDrag(({ down, movement: [mx, my] }) => {
    set({ x: down ? mx : 0, y: down ? my : 0 })
  })

  // Bind it to a component
  return <animated.div {...bind()} style={{ x, y }} />

The example above makes a div draggable so that it follows your mouse on drag, and returns to its initial position on release.

Available hooks

React-use-gesture exports several hooks that can handle different gestures:

Hook Description
useDrag Handles the drag gesture
useMove Handles mouse move events
useHover Handles mouse enter and mouse leave events
useScroll Handles scroll events
useWheel Handles wheel events
usePinch Handles the pinch gesture
useGesture Handles multiple gestures in one hook

More on the full documentation website...

You can’t perform that action at this time.