HomeReact
Chapter 25
25 — Animations in React
Animation techniques for React — from CSS transitions to production animation libraries.
Animation Approaches
| Approach | Best For | Performance |
|---|---|---|
| CSS Transitions | Simple hover/toggle effects | Excellent |
| CSS @keyframes | Looping, complex sequences | Excellent |
| Framer Motion | Declarative, layout, gestures | Great |
| React Spring | Physics-based, natural motion | Great |
| CSS Modules + classes | Toggle-based animations | Excellent |
| GSAP | Timeline-based, complex sequences | Great |
| Web Animations API | Low-level, imperative | Excellent |
Performance Rules
- Animate only
transformandopacity— they don't trigger layout recalculation - Use
will-changesparingly for GPU acceleration - Prefer CSS transitions over JS for simple animations
- Use
requestAnimationFramefor imperative JS animations
File
animations.tsx— CSS transitions, keyframes, Framer Motion patterns, mount/unmount animations, layout animations, gesture animations