'Can't get AnimatePresence in Framer Motion to work

I've been trying to get <AnimatePresence> from Framer Motion to work. But for some reason, I can't get it to work. I want to have an exit animation for a mobile navbar.

Here's a screenshot of the code: enter image description here

Here's the animation variables: enter image description here

It animates when en entering the DOM, but there's no animation when it leaves. Any help is greatly appreciated!

I've tried moving the different components around, but nothing seems to work.



Solution 1:[1]

From the Framer docs:

Child motion components must each have a unique key prop so AnimatePresence can track their presence in the tree.

You need to add a unique key prop to your m.ul element.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cadin