Exit animation not working
The exit animation for a <Header Component aint working and its already wrapper with Animate Presence
inside Header there is a multiple Links for a nested route , when i click to display the
BTW ive already tried wrapping the whole page with Animate Presence and its not working also
import { useEffect } from "react";
import { Outlet, useLocation } from "react-router-dom";
import Header from "../ui/Header";
import { AnimatePresence } from "framer-motion";
return (
<div>
<Header />
<div className="h-[90vh] bg-bg200 w-full overflow-hidden ">
<AnimatePresence mode="wait">
<Outlet />
</AnimatePresence>
</div>
</div>
);
}
export default Admin;
Header Code
export default function Header() {
const [isActive, setIsActive] = useState(false);
return (
<>
<div
onClick={() => {
setIsActive(!isActive);
}}
className={styles.button}
>
<div
className={`${styles.burger} ${isActive ? styles.burgerActive : ""}`}
></div>
<AnimatePresence mode="wait">{isActive && <Nav />}</AnimatePresence>
</div>
</>
);
}
You are probably missing the key attribute.
Try:
<AnimatePresence mode="wait">{isActive && <div key={"nav"}><Nav /></div>}</AnimatePresence>
The different elements being animated in/out have to have different keys
And don't forget
sadly it didnt work. when i navigate to other route inside the Admin page , exit animation doesnt work
I'm also seeing this bug using [email protected]
const CopyNotification = ({ isNotificationOpen }) => {
return (
<AnimatePresence>
{isNotificationOpen && (
<motion.div
key="copy-notification"
className="absolute left-1/2 top-0 z-50 select-none bg-white px-2 py-1 drop-shadow-lg before:absolute before:bottom-0 before:left-1/2 before:h-0 before:w-0 before:-translate-x-1/2 before:translate-y-full before:border-x-8 before:border-t-[8px] before:border-x-transparent before:border-t-white"
initial={{
opacity: 0,
x: "-50%",
y: "-50%",
scale: 0.2
}}
animate={{
opacity: 1,
y: "-120%",
scale: 1,
transition: { ease: "backInOut", duration: 0.2 }
}}
exit={{
opacity: 0,
transition: { ease: "easeOut", duration: 1 }
}}
>
Copied!
</motion.div>
)}
</AnimatePresence>
);
};
Probably there is an error in the navigating page, even key errors will cause the page to refresh
actually the page doesnt refresh , its SPA so everything working normally
Yeah, I see. Me as well after I fixed that thought it's gonna work, but it didn't
In the original example, the direct child of AnimatePresence isn't being unmounted.
Feel free to reopen with a sandbox example.
I'm also experiencing the same thing and have tried many ways to fix it, and I finally figured out which part is making it not work. I think the reason why the animation is not running is because of