useSpring for Single Values
What you'll learn: How to animate individual properties smoothly with React Spring's useSpring hook and fine-tune the physics behind the motion.
The Core Idea
useSpring is React Spring's foundational hook for animating one or more properties with spring-based physics. Unlike duration-based animations (like GSAP or CSS transitions), springs simulate real-world physics—think of a weight bobbing on an actual spring. You don't specify "animate for 500ms"; instead, you configure tension, friction, and mass to control how the spring behaves.
When animating a single value (or a few related properties), useSpring returns a style object you can spread directly onto elements:
import { useSpring, animated } from '@react-spring/web';
function BouncingBox() {
const springProps = useSpring({
from: { opacity: 0, transform: 'translateY(-50px)' },
to: { opacity: 1, transform: 'translateY(0px)' },
config: { tension: 180, friction: 12 }
});
return <animated.div style={springProps}>Hello Spring!</animated.div>;
}
Configuring Spring Physics
The config object controls how your spring behaves:
- tension: Higher values make the spring stiffer (faster, snappier motion)
- friction: Higher values create more resistance (dampens oscillation)
- mass: Heavier objects oscillate differently (adds weight feel)
Think of tension as how tightly wound the spring is, and friction as air resistance slowing it down.
// Gentle, floaty animation
config: { tension: 120, friction: 14 }
// Quick, snappy response
config: { tension: 300, friction: 10 }
React Spring also provides presets like config.gentle, config.wobbly, and config.stiff for common scenarios.
Key Takeaway: useSpring animates properties using physics-based springs rather than durations—configure tension, friction, and mass to control the feel of motion, and apply the returned style object to animated components.