Обновлено: 2026-06-10
React Use Gesture (@use-gesture/react) — библиотека для обработки жестов: перетаскивание, pinch, rotate, scroll. Удобна для интерактивных 3D-объектов.
import { useRef } from "react";
import { useFrame } from "@react-three/fiber";
import { useDrag } from "@use-gesture/react";
function DraggableBox() {
const meshRef = useRef();
const position = useRef([0, 0, 0]);
const bind = useDrag(({ offset: [x, y] }) => {
position.current = [x / 100, y / 100, 0];
});
useFrame(() => {
meshRef.current.position.x = position.current[0];
meshRef.current.position.y = position.current[1];
});
return (
<mesh ref={meshRef} {...bind()}>
<boxGeometry args={[1, 1, 1]} />
<meshStandardMaterial color="cyan" />
</mesh>
);
}
useDrag(
({ offset }) => { /* ... */ },
{ axis: "x", pointer: { touch: true } }
);
npm install @use-gesture/react