Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsJul 28, 2026·3 min de lectura

use-gesture — Component-Tied Gesture Handling for React and Vanilla JS

A utility library for binding mouse and touch gestures to UI components. Supports drag, pinch, scroll, wheel, and move gestures with configurable physics and bounds.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
use-gesture
Comando de instalación directa
npx -y tokrepo@latest install b5ae597c-8aa2-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

Introduction

use-gesture is a gesture library from the Poimandres collective (pmndrs) that binds rich pointer and touch interactions to components. It provides hooks for drag, pinch, scroll, wheel, move, and hover gestures, with built-in velocity tracking and configurable bounds, making interactive UIs straightforward to build.

What use-gesture Does

  • Provides React hooks for drag, pinch, scroll, wheel, move, and hover gestures
  • Tracks velocity, direction, distance, and offset for each gesture
  • Supports configurable bounds, thresholds, and axis locking
  • Works with any animation library (react-spring, framer-motion, CSS)
  • Offers a vanilla JS package for non-React projects

Architecture Overview

Each gesture hook registers pointer and touch event listeners on the target element. The library normalizes events across mouse, touch, and pointer APIs into a unified gesture state. On every event, it computes kinematic values (velocity, distance, direction) and calls your handler with the enriched state object. The library does not manage rendering; it only provides gesture data for your animation solution to consume.

Self-Hosting & Configuration

  • Install for React: npm install @use-gesture/react
  • Install for vanilla JS: npm install @use-gesture/vanilla
  • Use individual hooks (useDrag, usePinch) or useGesture for multiple gestures
  • Configure bounds: useDrag({ bounds: { left: -100, right: 100 } })
  • Set axis constraints: useDrag({ axis: "x" }) for horizontal-only dragging

Key Features

  • Unified gesture state with velocity and direction tracking
  • Built-in rubberbanding, swipe detection, and momentum
  • Works with any animation library or raw CSS transforms
  • Touch and pointer event normalization across devices
  • TypeScript support with strongly typed gesture state

Comparison with Similar Tools

  • react-dnd — Focused on drag-and-drop data transfer; use-gesture handles physics-based gestures
  • Hammer.js — Legacy gesture library; use-gesture is React-first with modern hooks API
  • Framer Motion (gestures) — Bundled with its animation engine; use-gesture is animation-agnostic
  • interact.js — Broader interaction library; use-gesture is lighter and hook-oriented

FAQ

Q: Does use-gesture work without react-spring? A: Yes. The gesture handlers provide raw values you can apply to any animation library, CSS variables, or direct style manipulation.

Q: Can I use use-gesture on mobile devices? A: Yes. It normalizes touch and pointer events and supports multi-touch gestures like pinch-to-zoom on mobile browsers.

Q: How do I combine multiple gestures on one element? A: Use the useGesture hook, which accepts handlers for multiple gesture types in a single call: useGesture({ onDrag: ..., onPinch: ... }).

Q: Is there a vanilla JavaScript version? A: Yes. The @use-gesture/vanilla package provides the same gesture engine without React dependencies.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados