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

Framer Motion for Component-Driven UI Animations

Choose Framer Motion when you need declarative animations tied to React state, layout shifts, or enter/exit transitions.

Framer Motion for Component-Driven UI Animations

What you'll learn: When to choose Framer Motion as your animation library for React applications.

The Sweet Spot for Framer Motion

You've now learned three animation approaches: CSS transitions, Framer Motion, and GSAP. Each has its place. Framer Motion shines when your animations are tightly coupled to React's component lifecycle and state.

Think of Framer Motion as "animations that speak React." While CSS transitions work for simple hover states and GSAP excels at complex imperative timelines, Framer Motion fits perfectly between them—when your UI changes are declarative, tied to component mounting/unmounting, or depend on React state updates.

When Framer Motion Is the Right Choice

Choose Framer Motion when you need:

  • State-driven animations: Your button expands when isOpen changes from false to true
  • Enter/exit transitions: Components animate in when they mount and out when they unmount (using AnimatePresence)
  • Layout animations: Elements smoothly reposition when their position in the DOM changes (the layout prop)
  • Shared element transitions: An image smoothly transitions from thumbnail to full-screen using layoutId
  • Declarative orchestration: Parent component state triggers coordinated child animations through variants

Framer Motion follows React's mental model: describe what the UI should look like, not how to get there. When your animation logic lives naturally inside your component's render cycle, Framer Motion keeps everything clean and maintainable.

Reserve CSS transitions for simple hover states. Save GSAP for when you need precise timeline control or imperative sequencing that doesn't fit React's declarative paradigm.

Key Takeaway: Choose Framer Motion when animations are driven by React state, component lifecycle, or layout changes—it's purpose-built for declarative, component-driven UI animations.