AnimatePresence
AnimatePresence keeps a leaving child in the DOM long enough for its exit animation to finish.
Wrap the conditional part of the tree, then put exit on the child you want to animate out.
✦
Props
mode-'sync'(default),'wait'(finish exits before entering), or'popLayout'initial- set tofalseto skip first-mount animationsonExitComplete- fires after all exiting children finish
<AnimatePresence mode="wait" initial={false} onExitComplete={() => undefined}>
{/* conditional child */}
</AnimatePresence>
Hello
See also
usePresence- read presence state from a child- Tabs example