Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
U

use-gesture

> 前端框架
Open source

Bread n butter utility for component-tied mouse/touch gestures in React and Vanilla Javascript.

9.6K stars0 likes2 views
WebsiteGitHub

About

Bread n butter utility for component-tied mouse/touch gestures in React and Vanilla Javascript.

@use-gesture

@use-gesture is a library 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

React

bash
#Yarn
yarn add @use-gesture/react

#NPM
npm install @use-gesture/react

Vanilla javascript

bash
#Yarn
yarn add @use-gesture/vanilla

#NPM
npm install @use-gesture/vanilla

Full documentation website

  • Available Gestures
  • Gesture State
  • Gesture Options
  • FAQ

Simple example

React
javascript
import { useSpring, animated } from '@react-spring/web'
import { useDrag } from '@use-gesture/react'

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

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

  // Bind it to a component.
  return <animated.div {...bind()} style={{ x, y, touchAction: 'none' }} />
}
Vanilla javascript
xml

<div id="drag" />
javascript
// script.js
const el = document.getElementById('drag')
const gesture = new DragGesture(el, ({ active, movement: [mx, my] }) => {
  setActive(active)
  anime({
    targets: el,
    translateX: active ? mx : 0,
    translateY: active ? my : 0,
    duration: active ? 0 : 1000
  })
})

// when you want to remove the listener
gesture.destroy()

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

@use-gesture/react 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...

Issues· 58 open

View all issuesOpen on GitHub
  • #711

    Maintenance: offering help with reviews, CI and releases

    Updated Sep 22, 2026
  • #692

    `transform` property breaks pinch and wheel actions

    Updated Sep 17, 2026
  • #701

    [Bug] `setPointerCapture` in `pointerDown` should be wrapped in try-catch

    Updated Mar 6, 2026
  • #690

    [Docs-Bug] - Main website fails on inital load

    Updated Jan 12, 2026
  • #622

    Pinch bug: after opening/closing context menu, pinching gesture can be fired with 1 finger

    bugUpdated Dec 25, 2025
  • #695

    usePinch cannot use with react-spring v10

    Updated Oct 23, 2025
  • #694

    From not recalculated after a tap when preventScroll is on in iOS

    Updated Oct 14, 2025
  • #593

    Combining filterTaps and preventScroll options on useDrag is breaking the onclick event on elements inside the drag container

    Updated Oct 7, 2025
  • #693

    Drag with `preventScroll`: pointerup is skipped if fires before timeout

    Updated Sep 13, 2025
  • #668

    Vanilla - Glitch during fast gestures

    Updated Apr 14, 2025

> Tags

TypeScriptdraggestureshookspinch

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 29, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架