Course contentsShow
← React
Lesson 1996 of 2,39645. AnimationsFree lesson

useTrail: Staggered Animations

Create trailing, staggered effects where elements follow each other with a slight delay using useTrail.

useTrail: Staggered Animations

You'll learn how to create elegant trailing effects where multiple elements animate in sequence with a slight delay between each one.

What is useTrail?

useTrail is React Spring's hook for creating staggered animations—think of a row of dominoes falling one after another, or a wave passing through a crowd. Instead of all elements animating simultaneously (like useSprings), each element follows the previous one with a subtle delay, creating a cascading visual effect.

This is perfect for animating lists, navigation items, or any collection of elements where you want to draw attention sequentially rather than all at once.

Basic Usage

import { useTrail, animated } from '@react-spring/web';

function StaggeredList() {
  const items = ['First', 'Second', 'Third', 'Fourth'];
  
  const trails = useTrail(items.length, {
    from: { opacity: 0, transform: 'translateY(20px)' },
    to: { opacity: 1, transform: 'translateY(0px)' },
  });

  return (
    <div>
      {trails.map((style, index) => (
        <animated.div key={index} style={style}>
          {items[index]}
        </animated.div>
      ))}
    </div>
  );
}

useTrail takes the number of elements and spring configuration. It returns an array of animated styles—one for each element—where each animation starts slightly after the previous one.

The Trailing Effect

The "trail" happens automatically: React Spring calculates delays so each element follows the leader. You don't manually set delay values; the library creates the stagger effect by chaining the animations together naturally, respecting the physics-based spring motion.

Key Takeaway: useTrail creates smooth, staggered animations where elements follow each other in sequence, perfect for lists and collections that need coordinated but delayed motion.