Animation & Transition Patterns
Smooth animations in React: Framer Motion patterns, React Spring, layout animations, gesture handling, and performance-optimized animations for production applications.
๐ฌ 1. Framer Motion Patterns
โจ Want your React app to feel alive? Framer Motion makes animations so easy it's almost cheating! ๐ฎ Declarative syntax, buttery-smooth transitions, layout animations, and drag gestures โ all with excellent performance out of the box. Your users will think you're a wizard! ๐งโโ๏ธ๐ซ
๐ Impact: HIGH โ Smooth animations are the secret sauce that makes apps feel polished and professional!
๐ In this section: Basic motion components โข Layout animations โข Gesture handling (drag) โข Enter/exit transitions
// โ Basic animationsimport { motion } from 'framer-motion';function AnimatedBox() {return (<motion.divinitial={{ opacity: 0, y: 20 }}animate={{ opacity: 1, y: 0 }}exit={{ opacity: 0, y: -20 }}transition={{ duration: 0.3 }}>Content</motion.div>);}// โ Layout animationsfunction LayoutAnimation() {return (<motion.div layout><motion.h2 layout>Title</motion.h2><motion.p layout>Content</motion.p></motion.div>);}// โ Gesture handlingfunction DraggableCard() {return (<motion.divdragdragConstraints={{ left: 0, right: 0, top: 0, bottom: 0 }}whileDrag={{ scale: 1.1 }}onDragEnd={(event, info) => {console.log('Drag ended', info.point);}}>Drag me</motion.div>);}