initial, animate, and exit states and the component handles the rest.
The more interesting question is what happens when basic entry and exit animations are not enough. Components that need to know they are leaving. Animations that depend on navigation direction. Parent-child exits that coordinate. This is where the real power lives.
Reading Presence State
Sometimes a component needs to know it is exiting. Maybe it changes its appearance, disables interactions, or triggers side effects. TheuseIsPresent hook provides this information.
- Disable buttons while a component exits
- Switch visual states on unmount
- Trigger cleanup when departure begins
Manual Exit Control
Standard exit animations run on a fixed timeline. But some scenarios require manual control. Async cleanup, external animation libraries, or coordinating with systems outside React. TheusePresence hook returns both the presence state and a safeToRemove callback. The component stays mounted until you call it.
safeToRemove is called, the element unmounts. This is how you could:
- Save draft content before a modal closes
- Wait for a network request to complete
- Hand control to GSAP or other animation libraries for more complex animations
Nested Exits
When a parent Animate Presence removes its children, nested exit animations do not fire by default. The parent wins. Sometimes you want both. A modal fading out while its content items also animate. Thepropagate prop enables this.
Modes
Themode prop controls timing between entering and exiting elements.
sync
This is where entering and exiting elements animate simultaneously. It’s useful for crossfades or when you want to animate both at the same time.You just have to bare in mind that both elements will be visible at the same time so you will have to handle the layouts to avoid conflicts.
wait
Here the exiting element waits for one to finish before the other starts. I use this when I want a more elegant transition between two elements. When I don’t want to have both elements visible at the same time.popLayout
Using this mode removes exiting elements from document flow immediately. They become absolutely positioned, allowing surrounding content to reflow.Closing Thoughts
Even though CSS now has@starting-style for native exit animations, simple transitions no longer need JavaScript. But the patterns in this article do. Reading presence state, manual exit control, directional animations, coordinated nested exits are things that Animate Presence offers that CSS can’t at this point in time.
Animate Presence fills the gap between what CSS can handle and what real interfaces need. The component itself is simple, but hopefully this article has helped you understand how to use it to its fullest.
Resources
- Motion AnimatePresence Documentation - Full API including useIsPresent, usePresence, and usePresenceData
- GSAP - For complex animation sequences outside React’s lifecycle
- MDN @starting-style Documentation - Emerging CSS approach to entry animations