Motion values
Motion values are imperative numeric channels that drive style props without re-rendering. The three patterns below cover most of what you'll reach for: a draggable surface with derived visuals, a scroll-linked progress bar, and a single 0..1 signal fanning out to several derived values.
Draggable with derived opacity and rotation
useDrag returns motion values for the drag offset. Feed those into
useTransform to derive other style values from the drag position — opacity
that fades as the element moves off-axis, a tilt that follows the swipe
direction.
Three motion values feed one element: x drives the actual translation,
rotate and opacity are derived. Every value bypasses React renders —
the card responds frame-by-frame without scheduling a single update.
Scroll-linked progress bar
A single source of truth — scroll progress as a 0..1 motion value — drives
a progress bar's width. The browser scroll event fires often, but React
never re-renders during the scroll.
useTransform's unit-matched output range recognises both endpoints as
percentages, strips the unit, lerps numerically, and re-appends. The
returned motion value drops straight into the width slot — no manual
formatting, no per-frame setState.
One signal fanning out to many derived values
A single progress motion value can feed any number of derived values via
useTransform. The pattern scales — one update notifies every subscriber
in O(n) without touching React.
The first 40% of the progress holds the element invisible; the last 60% fades it in, slides it up, and scales it to size. Tuning the visual takes two number edits — no orchestration code.
Pairing with useSpring for momentum
Motion values bypass transition. When you want a tween on .set(target),
route the target through useSpring first:
useSpring returns a motion value that springs toward the latest target
on every .set(). The element binds to it like any other motion value;
no extra wiring on the consumer side.
Related
- Motion values reference — the full API.
- Animation — declarative
transition/enterStyle/exitStylemotion props.