Socket
Socket
Sign inDemoInstall

react-use-gesture

Package Overview
Dependencies
3
Maintainers
2
Versions
173
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-use-gesture

React hook for receiving gestures https://use-gesture.netlify.app


Version published
Weekly downloads
245K
increased by3.73%
Maintainers
2
Install size
1.02 MB
Created
Weekly downloads
 

Readme

Source

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:

HookDescription
useDragHandles the drag gesture
useMoveHandles mouse move events
useHoverHandles mouse enter and mouse leave events
useScrollHandles scroll events
useWheelHandles wheel events
usePinchHandles the pinch gesture
useGestureHandles multiple gestures in one hook
More on the full documentation website...

Keywords

FAQs

Last updated on 07 Mar 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc