react-use-gesture

hook for receiving gestures

This package is no longer maintained. Please use @use-gesture/react instead
Last updated 6 years ago by dbismut .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install react-use-gesture 
SYNC missed versions from official npm registry.

React UseGesture

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

React UseGesture 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 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, touchAction: 'none' }} />

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

Make sure you always set touchAction on a draggable element to prevent glitches with the browser native scrolling on touch devices.

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...

Current Tags

  • 7.0.0-alpha.37                                ...           alpha (5 years ago)
  • 7.0.0-beta.11                                ...           beta (5 years ago)
  • 9.1.3                                ...           latest (4 years ago)
  • 9.1.0-alpha.1                                ...           next (4 years ago)

173 Versions

  • 9.1.0 [deprecated]           ...           4 years ago
  • 9.1.0-alpha.1 [deprecated]           ...           4 years ago
  • 9.0.4 [deprecated]           ...           4 years ago
  • 9.0.3 [deprecated]           ...           4 years ago
  • 9.0.2 [deprecated]           ...           4 years ago
  • 9.0.1 [deprecated]           ...           4 years ago
  • 9.0.0 [deprecated]           ...           4 years ago
  • 9.0.0-beta.14 [deprecated]           ...           4 years ago
  • 9.0.0-beta.13 [deprecated]           ...           4 years ago
  • 9.1.3 [deprecated]           ...           4 years ago
  • 9.1.2 [deprecated]           ...           4 years ago
  • 9.1.1 [deprecated]           ...           4 years ago
  • 9.0.0-beta.12 [deprecated]           ...           4 years ago
  • 9.0.0-beta.11 [deprecated]           ...           4 years ago
  • 9.0.0-beta.10 [deprecated]           ...           4 years ago
  • 8.1.0-beta.9 [deprecated]           ...           4 years ago
  • 8.1.0-beta.8 [deprecated]           ...           4 years ago
  • 8.1.0-beta.7 [deprecated]           ...           4 years ago
  • 8.1.0-beta.6 [deprecated]           ...           4 years ago
  • 8.1.0-beta.5 [deprecated]           ...           4 years ago
  • 8.1.0-beta.4 [deprecated]           ...           4 years ago
  • 8.1.0-beta.3 [deprecated]           ...           4 years ago
  • 8.1.0-beta.2 [deprecated]           ...           4 years ago
  • 8.1.0-beta.1 [deprecated]           ...           4 years ago
  • 8.1.0-alpha.12 [deprecated]           ...           4 years ago
  • 8.1.0-alpha.11 [deprecated]           ...           4 years ago
  • 8.1.0-alpha.10 [deprecated]           ...           4 years ago
  • 8.1.0-alpha.9 [deprecated]           ...           4 years ago
  • 8.1.0-alpha.8 [deprecated]           ...           4 years ago
  • 8.1.0-alpha.7 [deprecated]           ...           4 years ago
  • 8.1.0-alpha.6 [deprecated]           ...           4 years ago
  • 8.1.0-alpha.5 [deprecated]           ...           4 years ago
  • 8.1.0-alpha.4 [deprecated]           ...           4 years ago
  • 8.1.0-alpha.3 [deprecated]           ...           4 years ago
  • 8.1.0-alpha.2 [deprecated]           ...           4 years ago
  • 8.1.0-alpha.1 [deprecated]           ...           4 years ago
  • 8.0.1 [deprecated]           ...           4 years ago
  • 8.0.0 [deprecated]           ...           4 years ago
  • 8.0.0-beta.3 [deprecated]           ...           4 years ago
  • 8.0.0-beta.2 [deprecated]           ...           4 years ago
  • 8.0.0-beta.1 [deprecated]           ...           4 years ago
  • 8.0.0-alpha.10 [deprecated]           ...           4 years ago
  • 8.0.0-alpha.9 [deprecated]           ...           4 years ago
  • 8.0.0-alpha.8 [deprecated]           ...           4 years ago
  • 8.0.0-alpha.7 [deprecated]           ...           4 years ago
  • 8.0.0-alpha.6 [deprecated]           ...           4 years ago
  • 8.0.0-alpha.5 [deprecated]           ...           4 years ago
  • 8.0.0-alpha.4 [deprecated]           ...           4 years ago
  • 8.0.0-alpha.3 [deprecated]           ...           4 years ago
  • 7.0.16 [deprecated]           ...           4 years ago
  • 8.0.0-alpha.2 [deprecated]           ...           5 years ago
  • 8.0.0-alpha.1 [deprecated]           ...           5 years ago
  • 7.0.15 [deprecated]           ...           5 years ago
  • 7.0.14 [deprecated]           ...           5 years ago
  • 7.0.13 [deprecated]           ...           5 years ago
  • 7.0.12 [deprecated]           ...           5 years ago
  • 7.0.11 [deprecated]           ...           5 years ago
  • 7.0.10 [deprecated]           ...           5 years ago
  • 7.0.9 [deprecated]           ...           5 years ago
  • 7.0.8 [deprecated]           ...           5 years ago
  • 7.0.7 [deprecated]           ...           5 years ago
  • 7.0.6 [deprecated]           ...           5 years ago
  • 7.0.5 [deprecated]           ...           5 years ago
  • 7.0.4 [deprecated]           ...           5 years ago
  • 7.0.3 [deprecated]           ...           5 years ago
  • 7.0.2 [deprecated]           ...           5 years ago
  • 7.0.1 [deprecated]           ...           5 years ago
  • 7.0.0 [deprecated]           ...           5 years ago
  • 7.0.0-beta.11 [deprecated]           ...           5 years ago
  • 7.0.0-beta.10 [deprecated]           ...           5 years ago
  • 7.0.0-beta.9 [deprecated]           ...           5 years ago
  • 7.0.0-beta.8 [deprecated]           ...           5 years ago
  • 7.0.0-beta.7 [deprecated]           ...           5 years ago
  • 7.0.0-beta.6 [deprecated]           ...           5 years ago
  • 7.0.0-beta.5 [deprecated]           ...           5 years ago
  • 7.0.0-beta.4 [deprecated]           ...           5 years ago
  • 7.0.0-beta.3 [deprecated]           ...           5 years ago
  • 7.0.0-beta.2 [deprecated]           ...           5 years ago
  • 7.0.0-beta.1 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.37 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.36 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.35 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.34 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.33 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.32 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.31 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.30 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.29 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.28 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.27 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.26 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.25 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.24 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.23 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.22 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.21 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.20 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.19 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.18 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.17 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.16 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.15 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.14 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.13 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.12 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.11 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.10 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.9 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.8 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.7 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.6 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.5 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.4 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.3 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.2 [deprecated]           ...           5 years ago
  • 7.0.0-alpha.1 [deprecated]           ...           5 years ago
  • 6.0.14 [deprecated]           ...           5 years ago
  • 6.0.13 [deprecated]           ...           5 years ago
  • 6.0.12 [deprecated]           ...           5 years ago
  • 6.0.11 [deprecated]           ...           5 years ago
  • 6.0.10 [deprecated]           ...           5 years ago
  • 6.0.9 [deprecated]           ...           5 years ago
  • 6.0.8 [deprecated]           ...           5 years ago
  • 6.0.7 [deprecated]           ...           5 years ago
  • 6.0.6 [deprecated]           ...           5 years ago
  • 6.0.5 [deprecated]           ...           5 years ago
  • 6.0.4 [deprecated]           ...           5 years ago
  • 6.0.3 [deprecated]           ...           5 years ago
  • 6.0.2 [deprecated]           ...           5 years ago
  • 6.0.2-beta.2 [deprecated]           ...           5 years ago
  • 6.0.2-beta.1 [deprecated]           ...           5 years ago
  • 6.0.1 [deprecated]           ...           5 years ago
  • 6.0.0 [deprecated]           ...           5 years ago
  • 6.0.0-alpha.6 [deprecated]           ...           5 years ago
  • 6.0.0-alpha.5 [deprecated]           ...           5 years ago
  • 6.0.0-beta.4 [deprecated]           ...           5 years ago
  • 6.0.0-beta.3 [deprecated]           ...           5 years ago
  • 6.0.0-beta.2 [deprecated]           ...           5 years ago
  • 6.0.0-beta.1 [deprecated]           ...           5 years ago
  • 5.2.4 [deprecated]           ...           5 years ago
  • 5.2.3 [deprecated]           ...           5 years ago
  • 5.2.2 [deprecated]           ...           5 years ago
  • 5.2.1 [deprecated]           ...           5 years ago
  • 5.2.0 [deprecated]           ...           5 years ago
  • 5.1.3 [deprecated]           ...           5 years ago
  • 5.1.3-beta.2 [deprecated]           ...           5 years ago
  • 5.1.3-beta.1 [deprecated]           ...           5 years ago
  • 5.2.0-beta.1 [deprecated]           ...           5 years ago
  • 5.1.2 [deprecated]           ...           6 years ago
  • 5.1.1 [deprecated]           ...           6 years ago
  • 5.1.0-beta.9 [deprecated]           ...           6 years ago
  • 5.1.0-beta.8 [deprecated]           ...           6 years ago
  • 5.1.0-beta.7 [deprecated]           ...           6 years ago
  • 5.1.0-beta.6 [deprecated]           ...           6 years ago
  • 5.0.2 [deprecated]           ...           6 years ago
  • 5.1.0-beta.5 [deprecated]           ...           6 years ago
  • 5.1.0-beta.4 [deprecated]           ...           6 years ago
  • 5.1.0-beta.3 [deprecated]           ...           6 years ago
  • 5.1.0-beta.2 [deprecated]           ...           6 years ago
  • 5.1.0-beta.1 [deprecated]           ...           6 years ago
  • 5.1.0 [deprecated]           ...           6 years ago
  • 5.0.1 [deprecated]           ...           6 years ago
  • 5.0.0 [deprecated]           ...           6 years ago
  • 5.0.0-beta.8 [deprecated]           ...           6 years ago
  • 5.0.0-beta.7 [deprecated]           ...           6 years ago
  • 5.0.0-beta.6 [deprecated]           ...           6 years ago
  • 5.0.0-beta.5 [deprecated]           ...           6 years ago
  • 5.0.0-beta.4 [deprecated]           ...           6 years ago
  • 5.0.0-beta.3 [deprecated]           ...           6 years ago
  • 5.0.0-beta.2 [deprecated]           ...           6 years ago
  • 5.0.0-beta.1 [deprecated]           ...           6 years ago
  • 5.0.0-beta.0 [deprecated]           ...           6 years ago
  • 1.0.0 [deprecated]           ...           6 years ago
Maintainers (1)
Downloads
Total 169
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE