THE PLAYGROUND · GESTURES
Swipe-to-dismiss
Swipe an item away to remove it from a list.
Swipe-to-dismissGestures · Swipe an item away to remove it from a list.
DRAG1import { useState } from "react";2import { motion } from "motion/react";3 4const surface = { width: 100, height: 100, borderRadius: 16, background: "#b8ed79", display: "grid", placeItems: "center", color: "#141714" };5 6export default function SwipeDismissDemo() {7 const [dismissed, setDismissed] = useState(false);8 const [rotation, setRotation] = useState(0);9 return <div style={{width: 320, overflow: "hidden"}}>10 <button onClick={() => {setDismissed(false); setRotation(0);}}>Reset</button>11 {!dismissed && <motion.div style={surface} drag="x" dragConstraints={{left: 0, right: 0, top: 0, bottom: 0}} dragElastic={0.25} animate={{rotate: rotation}} transition={{ type: "spring", stiffness: 180, damping: 14, mass: 1 }}12 onDrag={(_, info) => undefined}13 onDragEnd={(_, info) => { if (info.offset.x < -60) setDismissed(true); }}>Drag me</motion.div>}14 15 </div>;16}Install: npm install motion. Only remove the item after a clear threshold. This compact example illustrates the core technique; the styled playground contains additional presentation details.