Socket
Socket
Sign inDemoInstall

@use-gesture/react

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@use-gesture/react

React target for @use-gesture


Version published
Weekly downloads
652K
increased by3.63%
Maintainers
1
Weekly downloads
 
Created

What is @use-gesture/react?

@use-gesture/react is a library that provides a set of hooks to handle gestures in React applications. It allows developers to easily add touch and pointer event handling to their components, supporting gestures like dragging, pinching, scrolling, and more.

What are @use-gesture/react's main functionalities?

Drag

This code demonstrates how to use the `useDrag` hook to make a div element draggable. The position of the element is updated based on the drag state.

```jsx
import { useDrag } from '@use-gesture/react';
import { useState } from 'react';

function Draggable() {
  const [position, setPosition] = useState({ x: 0, y: 0 });
  const bind = useDrag((state) => {
    setPosition({ x: state.offset[0], y: state.offset[1] });
  });

  return (
    <div
      {...bind()}
      style={{
        transform: `translate3d(${position.x}px, ${position.y}px, 0)`,
        width: 100,
        height: 100,
        background: 'lightblue',
      }}
    />
  );
}
```

Pinch

This code demonstrates how to use the `usePinch` hook to make a div element pinchable. The scale of the element is updated based on the pinch state.

```jsx
import { usePinch } from '@use-gesture/react';
import { useState } from 'react';

function Pinchable() {
  const [scale, setScale] = useState(1);
  const bind = usePinch((state) => {
    setScale(state.offset[0]);
  });

  return (
    <div
      {...bind()}
      style={{
        transform: `scale(${scale})`,
        width: 100,
        height: 100,
        background: 'lightcoral',
      }}
    />
  );
}
```

Scroll

This code demonstrates how to use the `useScroll` hook to handle scroll events. The scroll position is updated based on the scroll state.

```jsx
import { useScroll } from '@use-gesture/react';
import { useState } from 'react';

function Scrollable() {
  const [scroll, setScroll] = useState({ x: 0, y: 0 });
  const bind = useScroll((state) => {
    setScroll({ x: state.offset[0], y: state.offset[1] });
  });

  return (
    <div
      {...bind()}
      style={{
        width: 200,
        height: 200,
        overflow: 'auto',
        background: 'lightgreen',
      }}
    >
      <div style={{ width: 400, height: 400 }}>
        Scroll me!
      </div>
    </div>
  );
}
```

Other packages similar to @use-gesture/react

Keywords

FAQs

Package last updated on 21 Mar 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc