Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-use-gesture

Package Overview
Dependencies
Maintainers
2
Versions
173
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-gesture

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

  • 9.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
192K
decreased by-6.37%
Maintainers
2
Weekly downloads
 
Created

What is react-use-gesture?

react-use-gesture is a React hook library that allows you to handle gestures in your React applications. It provides a simple and declarative way to manage complex gesture interactions such as dragging, pinching, and scrolling.

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

Drag

The `useDrag` hook allows you to handle drag gestures. In this example, the `bind` function is used to attach the drag event to a `div` element. The `offset` property provides the current position of the dragged element.

```jsx
import React from 'react';
import { useDrag } from 'react-use-gesture';

function Draggable() {
  const bind = useDrag(({ offset: [x, y] }) => {
    console.log(`Dragged to: ${x}, ${y}`);
  });

  return <div {...bind()} style={{ width: 100, height: 100, background: 'lightblue' }}>Drag me</div>;
}

export default Draggable;
```

Pinch

The `usePinch` hook allows you to handle pinch gestures. In this example, the `bind` function is used to attach the pinch event to a `div` element. The `offset` property provides the current distance and angle of the pinch gesture.

```jsx
import React from 'react';
import { usePinch } from 'react-use-gesture';

function Pinchable() {
  const bind = usePinch(({ offset: [d, a] }) => {
    console.log(`Pinched to: ${d}, ${a}`);
  });

  return <div {...bind()} style={{ width: 100, height: 100, background: 'lightgreen' }}>Pinch me</div>;
}

export default Pinchable;
```

Scroll

The `useScroll` hook allows you to handle scroll gestures. In this example, the `bind` function is used to attach the scroll event to a `div` element. The `offset` property provides the current scroll position.

```jsx
import React from 'react';
import { useScroll } from 'react-use-gesture';

function Scrollable() {
  const bind = useScroll(({ offset: [x, y] }) => {
    console.log(`Scrolled to: ${x}, ${y}`);
  });

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

export default Scrollable;
```

Other packages similar to react-use-gesture

Keywords

FAQs

Package last updated on 07 Mar 2021

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