AnimatePresence component enables exit animations for motion components. When a motion component is removed from the tree, AnimatePresence keeps it rendered until its exit animation completes.
Usage
Multiple Children
When animating multiple children, each must have a uniquekey prop:
Props
React children. Any
motion components with an exit prop will animate out when removed.By passing
initial={false}, AnimatePresence will disable any initial animations on children that are present when the component first renders.Determines how entering and exiting elements are handled:
"sync": Elements animate in and out as soon as they’re added/removed (default)"wait": Only renders one component at a time. Waits for the exiting component to finish before animating the next one in"popLayout": Exiting elements are “popped” from the page layout, allowing siblings to immediately move to their new positions
Fires when all exiting nodes have completed animating out.
When a component is removed, there’s no longer a chance to update its props. Use
custom to pass dynamic data to the exit animation via variants.Internal prop used in Framer to control whether sibling children should re-render when a child is removed.
If
true, the AnimatePresence component will propagate parent exit animations to its children.Root element for injecting styles when using
mode="popLayout". Defaults to document.head.Use this for Shadow DOM or other custom contexts.Examples
List with Staggered Exit
Modal with Backdrop
Page Transitions
TypeScript
Notes
- Children must have a unique
keyprop when animating multiple elements - Only direct children of
AnimatePresencewill animate out - The component being removed must have an
exitprop defined - Multiple
motioncomponents in a single child will all need to complete their exit animations before unmounting
Related
- motion - Core animation component
- exit animation guide - Learn more about exit animations