If a component with a layoutId is added, and the existing component with that same layoutId is still rendered, the older component will automatically be hidden. The new component will animate out from its position.

By wrapping the new component in AnimatePresence , when it's removed it'll automatically animate back to the original component's position as an exit animation.