Back to Explore
THE PLAYGROUND · GESTURES

Pull-to-refresh

Pull a list downward to request fresh content.

Pull-to-refreshGestures · Pull a list downward to request fresh content.
DRAG
Pull down to refresh
Fresh inspiration
New perspectives
Your daily discoveries
DRAG TO INTERACT · 600 ms
1import { 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 PullRefreshDemo() {7  const [updates, setUpdates] = useState(0);8  const [pull, setPull] = useState(0);9  return <div style={{height: 260, overflow: "hidden"}}>10    <motion.div drag="y" dragConstraints={{top: 0, bottom: 0}} dragElastic={.6} transition={{ type: "spring", stiffness: 180, damping: 14, mass: 1 }}11      onDrag={(_, info) => setPull(Math.max(0, info.offset.y))}12      onDragEnd={(_, info) => { if (info.offset.y > 50) setUpdates(v => v + 1); setPull(0); }}>13      <p>{pull > 50 ? "Release to refresh" : "Pull down"}</p>14      <p>Refreshed {updates} times</p>15      {[0,1,2].map(n => <p key={n}>Feed item {n + updates + 1}</p>)}16    </motion.div>17  </div>;18}

Install: npm install motion. Refresh only after the pull crosses a threshold. This compact example illustrates the core technique; the styled playground contains additional presentation details.