Swipe actions: Step-by-step tutorial

Matt Perry
In this tutorial, we're going to build the Swipe actions example step-by-step.
This example is rated 4/5 difficulty, which means we assume you're already quite familiar with Motion (and JavaScript in general).
Here's a live demo of the example we're going to be creating:
Checking Motion+ status…
The Swipe actions tutorial
is exclusive to Motion+
290+ examples & 35+ tutorials
Premium APIs
Visual editor for VS Code
alpha
Discord community
Early access
Lifetime updates
One-time payment, lifetime updates
Already joined?
Introduction
The Swipe actions example shows how to implement an iOS-style swipe gesture interface where swiping an item left or right reveals contextual actions. This pattern is commonly used in mobile UIs for actions like archive, delete, or flag, providing a space-efficient alternative to having these actions permanently visible.
This tutorial explores several advanced Motion for React APIs:
useMotionValue
to track the swipe positionuseTransform
to derive styles from the swipe amountuseSpring
to add realistic physics to the animationsanimate
to manually trigger animationsuseMotionValueEvent
to trigger events when motion values change