The mode Prop: wait, sync, and popLayout
What you'll learn: How to control the timing relationship between exiting and entering animations when AnimatePresence manages multiple children.
The Problem
When you swap components inside AnimatePresence (like switching between different routes or tabs), you face a timing question: Should the old component finish exiting before the new one enters? Should they animate simultaneously? Should layout changes happen immediately?
The Three Modes
The mode prop on AnimatePresence controls this coordination:
sync (default)
Both exit and enter animations happen at the same time. Think of two actors crossing a stage simultaneously—one walks off while the other walks on. This creates smooth, overlapping transitions but can feel busy if both components occupy similar space.
<AnimatePresence mode="sync">
{showA ? <ComponentA key="a" /> : <ComponentB key="b" />}
</AnimatePresence>
wait
The exiting component completes its animation first, then the entering component animates in. Like one actor leaving the stage completely before the next one enters. This prevents visual overlap but introduces a brief pause.
<AnimatePresence mode="wait">
{currentPage === 'home' ? <Home key="home" /> : <About key="about" />}
</AnimatePresence>
popLayout
Optimized for layout animations. The exiting component is instantly removed from layout calculations (preventing layout shift), but its exit animation still plays. Useful when removing items from lists without causing jarring reflows.
<AnimatePresence mode="popLayout">
{items.map(item => <Item key={item.id} />)}
</AnimatePresence>
Choosing the Right Mode
Use wait for full-screen transitions where overlap feels wrong. Use sync when smooth crossfades look natural. Use popLayout when removing items from grids or lists.
Key Takeaway: The mode prop controls whether AnimatePresence children exit and enter simultaneously (sync), sequentially (wait), or with immediate layout removal (popLayout), giving you precise control over multi-component animation timing.