HomeReact
Chapter 25

25 — Animations in React

Animation techniques for React — from CSS transitions to production animation libraries.

Animation Approaches

ApproachBest ForPerformance
CSS TransitionsSimple hover/toggle effectsExcellent
CSS @keyframesLooping, complex sequencesExcellent
Framer MotionDeclarative, layout, gesturesGreat
React SpringPhysics-based, natural motionGreat
CSS Modules + classesToggle-based animationsExcellent
GSAPTimeline-based, complex sequencesGreat
Web Animations APILow-level, imperativeExcellent

Performance Rules

  1. Animate only transform and opacity — they don't trigger layout recalculation
  2. Use will-change sparingly for GPU acceleration
  3. Prefer CSS transitions over JS for simple animations
  4. Use requestAnimationFrame for imperative JS animations

File

  • animations.tsx — CSS transitions, keyframes, Framer Motion patterns, mount/unmount animations, layout animations, gesture animations