useChain for Orchestration
What you'll learn: How to coordinate multiple React Spring animation hooks in precise sequence using useChain for complex choreographed effects.
The Conductor of Animation Hooks
When you've built animations with useSpring, useSprings, useTransition, and useTrail, you often need them to play in a specific order—like dancers entering the stage one after another. useChain is React Spring's way of orchestrating these different animation hooks into a synchronized sequence.
Think of useChain as a conductor for an orchestra: each animation hook is an instrument, and useChain tells them exactly when to start playing relative to each other.
How It Works
Each animation hook (like useSpring or useTransition) can return a ref that useChain uses to control timing. You pass an array of these refs to useChain, and it plays them in sequence:
const springRef = useRef();
const spring = useSpring({
ref: springRef,
from: { opacity: 0 },
to: { opacity: 1 }
});
const trailRef = useRef();
const trail = useTrail(5, {
ref: trailRef,
from: { x: -100 },
to: { x: 0 }
});
// Spring plays first, then trail
useChain([springRef, trailRef]);
You can also control when each animation starts using position values (0 to 1 representing the timeline):
// Trail starts 30% into the timeline
useChain([springRef, trailRef], [0, 0.3]);
This creates a smooth handoff where the trail begins before the spring fully completes.
Why It Matters
Complex UI choreography—like content fading in, then cards staggering into view, then a button appearing—requires precise timing. useChain eliminates manual delay calculations and keeps your animation logic declarative and maintainable.
Key Takeaway: useChain orchestrates multiple React Spring animation hooks by controlling their execution order and relative timing through refs, enabling complex, synchronized animation sequences.