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

@use-gesture/core

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/core

Core engine for receiving gestures

  • 10.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
651K
decreased by-1.56%
Maintainers
1
Weekly downloads
 
Created

What is @use-gesture/core?

@use-gesture/core is a library for handling gestures in React applications. It provides a set of hooks that allow you to easily add gesture recognition to your components, such as drag, pinch, scroll, wheel, and more.

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

Drag

This code sample demonstrates how to use the `useDrag` hook to make a component draggable. The `useDrag` hook provides the necessary bindings to track the drag state and update the component's position accordingly.

```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 sample demonstrates how to use the `usePinch` hook to make a component pinchable. The `usePinch` hook provides the necessary bindings to track the pinch state and update the component's scale accordingly.

```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 sample demonstrates how to use the `useScroll` hook to handle scroll events. The `useScroll` hook provides the necessary bindings to track the scroll state and update the component's scroll position accordingly.

```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/core

FAQs

Package last updated on 11 Dec 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