Skip to content

Framer Motion AnimatePresence Not Working — Fix Exit Animations

DodaTech Updated 2026-06-24 1 min read

In this fix, you'll learn how to animate element removal with AnimatePresence. This matters for smooth content transitions, and appears in modal dialogs and tab panels.

The Problem

The following code demonstrates the typical mistake:

{isOpen && <motion.div>Content</motion.div>}
// Content disappears instantly when isOpen becomes false

The Fix

Here is the corrected version:

import { AnimatePresence, motion } from 'framer-motion';
<AnimatePresence>
  {isOpen && (
    <motion.div
      initial={{ opacity: 0, y: -20 }}
      animate={{ opacity: 1, y: 0 }}
      exit={{ opacity: 0, y: -20 }}
    >
      Content
    </motion.div>
  )}
</AnimatePresence>
// Content animates out before being removed from DOM

Prevention

  • Wrap conditional elements in AnimatePresence for exit animations.
  • Always define an exit prop on the motion element.
  • Place AnimatePresence around the toggle point, not nested deeply.
  • Use mode='wait' to wait for exit before entering new elements.
  • Use onExitComplete callback to run logic after animations finish.

Common Mistakes with framer motion animate presence

  1. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  2. Misunderstanding that String is [Char] with poor performance for large text operations
  3. Using foldl instead of foldl' causing stack overflow on large lists

These mistakes appear frequently in real-world REACT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### How does AnimatePresence work?

It tracks elements removed from the React tree. When removed, it keeps the element in the DOM, plays the exit animation, then unmounts it after the animation completes.

Why is my exit animation not playing?

Common causes: (1) missing exit prop, (2) same key between entering/exiting elements (need unique keys), (3) AnimatePresence not directly wrapping the conditional.

What does mode='wait' do?

It waits for exit animations to complete before rendering entering elements. Without it (mode='sync'), both play simultaneously.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro