framer-motion-best-practices
191
总安装量
191
周安装量
#1404
全站排名
安装命令
npx skills add https://github.com/pproenca/dot-skills --skill framer-motion-best-practices
Agent 安装分布
opencode
152
gemini-cli
149
codex
144
github-copilot
121
antigravity
113
Skill 文档
Community Framer Motion Best Practices
Comprehensive performance optimization guide for Framer Motion animations in React applications. Contains 42 rules across 9 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Adding animations to React components with Framer Motion
- Optimizing bundle size for animation-heavy applications
- Preventing unnecessary re-renders during animations
- Implementing layout transitions or shared element animations
- Building scroll-linked or gesture-based interactions
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Bundle Optimization | CRITICAL | bundle- |
| 2 | Re-render Prevention | CRITICAL | rerender- |
| 3 | Animation Properties | HIGH | anim- |
| 4 | Layout Animations | HIGH | layout- |
| 5 | Scroll Animations | MEDIUM-HIGH | scroll- |
| 6 | Gesture Optimization | MEDIUM | gesture- |
| 7 | Spring & Physics | MEDIUM | spring- |
| 8 | SVG & Path Animations | LOW-MEDIUM | svg- |
| 9 | Exit Animations | LOW | exit- |
Quick Reference
1. Bundle Optimization (CRITICAL)
bundle-lazy-motion– Use LazyMotion and m component instead of motionbundle-dynamic-features– Dynamically import motion featuresbundle-dom-animation– Use domAnimation for basic animationsbundle-use-animate-mini– Use mini useAnimate for simple casesbundle-strict-mode– Enable strict mode to catch accidental imports
2. Re-render Prevention (CRITICAL)
rerender-motion-value– Use useMotionValue instead of useStatererender-use-transform– Derive values with useTransformrerender-stable-callbacks– Keep animation callbacks stablererender-variants-object– Define variants outside componentrerender-animate-prop– Use stable animate valuesrerender-motion-value-event– Use motion value events
3. Animation Properties (HIGH)
anim-transform-properties– Animate transform propertiesanim-opacity-filter– Prefer opacity and filter for visual effectsanim-hardware-acceleration– Leverage hardware accelerationanim-will-change– Use willChange prop judiciouslyanim-independent-transforms– Animate transforms independentlyanim-keyframes-array– Use keyframe arrays for sequences
4. Layout Animations (HIGH)
layout-dependency– Use layoutDependency to limit measurementslayout-position-size– Use layout=”position” or “size” appropriatelylayout-group– Group related layout animationslayout-id-shared– Use layoutId for shared element transitionslayout-scroll– Add layoutScroll to scrollable ancestors
5. Scroll Animations (MEDIUM-HIGH)
scroll-use-scroll– Use useScroll hook for scroll-linked animationsscroll-use-spring-smooth– Smooth scroll animations with useSpringscroll-element-tracking– Track specific elements entering viewportscroll-offset-configuration– Configure scroll offsetsscroll-container-ref– Track scroll within specific containers
6. Gesture Optimization (MEDIUM)
gesture-while-props– Use whileHover/whileTap instead of handlersgesture-variants-flow– Let gesture variants flow to childrengesture-drag-constraints– Use dragConstraints ref for boundariesgesture-drag-elastic– Configure dragElastic for natural feelgesture-tap-cancel– Use onTapCancel for interrupted gestures
7. Spring & Physics (MEDIUM)
spring-physics-based– Use physics-based springs for interruptibilityspring-damping-ratio– Configure damping to control oscillationspring-mass-inertia– Adjust mass for heavier/lighter feelspring-use-spring-hook– Use useSpring for reactive values
8. SVG & Path Animations (LOW-MEDIUM)
svg-path-length– Use pathLength for line drawing animationssvg-motion-components– Use motion.path and motion.circlesvg-viewbox-animation– Animate viewBox for zoom effectssvg-morph-matching-points– Match point counts for morphing
9. Exit Animations (LOW)
exit-animate-presence– Wrap conditional renders with AnimatePresenceexit-unique-keys– Provide unique keys for AnimatePresence childrenexit-mode-wait– Use mode=”wait” for sequential transitions
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions – Category structure and impact levels
- Rule template – Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |