Course contentsShow
← Web Development
Lesson 2575 of 2,98246. Animation LibrariesFree lesson

useSprings for Multiple Elements

Animating arrays of elements with useSprings, managing multiple spring instances with shared configurations.

useSprings for Multiple Elements

What you'll learn: How to animate multiple elements simultaneously using React Spring's useSprings hook with shared or individual configurations.

The Core Idea

While useSpring handles a single animated value, useSprings (plural) manages an array of springs — one for each element you want to animate. Think of it like conducting an orchestra: instead of focusing on one musician, you're directing multiple performers who can follow the same sheet music or play different parts entirely.

useSprings takes two main arguments: the number of springs you need, and a function that returns configuration for each spring. This function receives the index of each element, letting you create staggered effects, unique values, or shared animations.

Basic Structure

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

function ItemList({ items }) {
  const springs = useSprings(
    items.length,
    items.map((item, index) => ({
      from: { opacity: 0, transform: 'translateY(20px)' },
      to: { opacity: 1, transform: 'translateY(0px)' },
      delay: index * 100 // stagger each item
    }))
  );

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

Shared vs Individual Configurations

You can give all springs identical configurations or customize each one using the index parameter. For example, alternating opacity levels or creating wave-like motion patterns where each element's timing relates to its position.

Managing Updates

When your data changes, useSprings intelligently updates only what's necessary, maintaining smooth performance even with many animated elements.

Key Takeaway: useSprings extends React Spring's capabilities to arrays of elements, enabling coordinated multi-element animations with shared or index-based individual configurations — perfect for lists, grids, and sequential UI transitions.