Course contentsShow
← React
Lesson 1267 of 2,39632. Lists and Keys Deep DiveFree lesson

Animation and Transition Breaks

Why animations restart or skip when React treats items as new instead of moved or updated.

Animation and Transition Breaks

You'll learn: How unstable keys cause animations to restart or skip instead of smoothly transitioning when list items change.

When React encounters a key it hasn't seen before, it treats that element as completely new—mounting it from scratch. When a key disappears, React unmounts that element entirely. This mounting/unmounting behavior destroys any ongoing animations or transitions.

The Problem in Action

Imagine you're animating a list item sliding from one position to another. If you're using index-based keys and the list order changes:

// Before sort: Item "B" has key={1}
<AnimatedItem key={1}>B</AnimatedItem>

// After sort: Item "B" now has key={0}
<AnimatedItem key={0}>B</AnimatedItem>

React sees key={1} disappear and key={0} appear. It unmounts the old component (canceling any running animation) and mounts a new one (restarting the animation from the beginning). Your smooth slide-to-new-position becomes a jarring restart.

Why Stable Keys Fix This

With stable ID-based keys, React recognizes the same item in a new position:

// Before and after sort: same key, different position
<AnimatedItem key="item-b">B</AnimatedItem>

React knows this is the same component moving, not a new one appearing. Animation libraries can detect the position change and smoothly transition. The component instance persists, preserving animation state.

The Analogy

Think of a performer on stage with a name tag. If they move left to right, the audience follows them smoothly. But if you rip off their name tag and slap it on someone else, the audience thinks the first person left and a new person appeared—continuity is broken.

Key Takeaway: Unstable keys cause React to mount/unmount components instead of moving them, destroying animation state and making transitions restart or skip. Stable keys preserve component identity so animations can transition smoothly between positions.