AnimatePresence allows components to animate when they're removed from the React tree. Once the elements are wrapped in AnimatePresence you get access to the exit prop which animate the element when it is removed.
AnimatePresence