What You'll Learn
You'll learn how to animate entire lists or collections of elements in a coordinated way using React Spring's useSprings hook.
Why useSprings Exists
When you need to animate multiple elements — like a list of cards, a grid of items, or a set of navigation links — you could use multiple useSpring calls, but that becomes unwieldy fast. useSprings is designed specifically for this: animating N elements from a single hook call, where each element gets its own independent spring animation.
Think of it like a choreographer managing multiple dancers: each dancer performs their own moves, but the choreographer controls them all with one set of instructions.
How useSprings Works
import { useSprings, animated } from '@react-spring/web';
const items = ['Item 1', 'Item 2', 'Item 3'];
function ListAnimation() {
const springs = useSprings(
items.length,
items.map((item, i) => ({
from: { opacity: 0, transform: 'translateY(20px)' },
to: { opacity: 1, transform: 'translateY(0px)' },
delay: i * 100, // Stagger each item
}))
);
return (
<div>
{springs.map((style, i) => (
<animated.div key={i} style={style}>
{items[i]}
</animated.div>
))}
</div>
);
}
Key points:
- First argument: number of springs (typically
array.length) - Second argument: array of spring configs, one per element
- Returns an array of animated styles, which you map over to render
You can stagger animations with delay, create wave effects by varying timing, or make each element respond to different data entirely.
Key Takeaway: useSprings lets you animate collections of elements by mapping over your data and generating coordinated, independent spring animations for each item — perfect for lists, grids, and staggered reveals.