└── README.md /README.md: -------------------------------------------------------------------------------- 1 | 1. AnimatePresence Best Practices: 2 | ```jsx 3 | // ❌ Element disappears instantly 4 | {isVisible && } 5 | 6 | // ✅ Element animates out properly 7 | 8 | {isVisible && ( 9 | 15 | )} 16 | 17 | ``` 18 | 19 | 2. Layering for Complex Animations: 20 | ```jsx 21 | // Like in the trash example 22 | 23 | {/* Behind stuff */} 24 | {/* Moving content */} 25 | {/* Mask or overlay */} 26 | 27 | ``` 28 | 29 | 3. Delays for Natural Sequences: 30 | ```jsx 31 | // Stagger children 32 | 33 | 34 | 35 | 36 | 37 | ``` 38 | 39 | 4. Blur + Scale for Depth: 40 | ```jsx 41 | 46 | ``` 47 | 48 | 5. Layout Transitions: 49 | ```jsx 50 | // Smooth height/width changes 51 | 52 | {expanded && } 53 | 54 | 55 | // Position-only for text 56 | 57 | Title 58 | 59 | ``` 60 | 61 | 6. Coordinated Animations with LayoutId: 62 | ```jsx 63 | // From list to modal 64 | 65 | {isExpanded ? : } 66 | 67 | ``` 68 | 69 | 7. Mode Controls for AnimatePresence: 70 | ```jsx 71 | // Wait for exit before enter 72 | 73 | 74 | // Pop out of layout flow during exit 75 | 76 | ``` 77 | 78 | 8. Spring Transitions for Natural Feel: 79 | ```jsx 80 | 87 | 88 | 89 | ``` 90 | 91 | 9. Handling Complex State Sequences: 92 | ```jsx 93 | // Like in trash example 94 | useEffect(() => { 95 | if (isExiting) { 96 | // Sequence of state changes 97 | const t1 = setTimeout(() => setPhase1(true), 300) 98 | const t2 = setTimeout(() => setPhase2(true), 600) 99 | return () => { 100 | clearTimeout(t1) 101 | clearTimeout(t2) 102 | } 103 | } 104 | }, [isExiting]) 105 | ``` 106 | 107 | 10. Using Custom Props for Dynamic Variants: 108 | ```jsx 109 | 110 | ({ 114 | x: direction === 'left' ? -100 : 100 115 | }) 116 | }} 117 | /> 118 | 119 | ``` 120 | --------------------------------------------------------------------------------