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

Installing and Setting Up React Spring

Add react-spring to your project and understand the core hooks: useSpring, useSprings, useTrail, useChain.

Installing and Setting Up React Spring

What you'll learn: How to add react-spring to your React project and understand its core animation hooks.

Why React Spring?

You've already explored physics-based animations conceptually. React-spring is the library that brings those physics principles to React through a clean, hook-based API. Instead of specifying durations, you configure mass, tension, and friction—letting natural motion emerge.

Installation

Add react-spring to your project:

npm install @react-spring/web

The @react-spring/web package is the modern version optimized for web applications (there are separate packages for React Native and other platforms).

Core Hooks Overview

React-spring provides four primary hooks, each serving different animation patterns:

useSpring

Animates a single element from one state to another. Think of it as animating one ball bouncing from point A to point B.

useSprings

Animates multiple elements with independent configurations. Like animating several balls, each with its own trajectory.

useTrail

Animates multiple elements in sequence, where each follows the previous one. Imagine a line of dominoes falling—each starts after the one before it.

useChain

Orchestrates multiple animations to run in a specific order. You control the choreography: "first animate this, then that."

Basic Import Pattern

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

The animated component wrapper is how you tell react-spring which elements to animate—you'll pair it with the hooks in the next lessons.

Key Takeaway: React-spring adds physics-based animation through four core hooks—useSpring for single elements, useSprings for multiple independent animations, useTrail for sequential animations, and useChain for orchestrating complex sequences.