
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@use-gesture/core
Advanced tools
@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.
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>
);
}
```
react-use-gesture is a library similar to @use-gesture/core that provides hooks for handling gestures in React applications. It offers a similar API and functionality, making it a good alternative for gesture recognition in React.
react-draggable is a library focused on making elements draggable in React applications. While it does not offer the full range of gesture recognition provided by @use-gesture/core, it is a robust solution for drag-and-drop functionality.
react-spring is a library for animating React components. It can be used in conjunction with gesture libraries like @use-gesture/core to create smooth, animated interactions. While it is not a gesture library itself, it complements gesture handling by providing powerful animation capabilities.
FAQs
Core engine for receiving gestures
The npm package @use-gesture/core receives a total of 494,364 weekly downloads. As such, @use-gesture/core popularity was classified as popular.
We found that @use-gesture/core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.