Installation
Install React Transition Group via npm or yarn:Basic usage
React Transition Group provides low-level components for managing transitions. It doesn’t animate styles directly but exposes transition stages you can hook into.CSSTransition
The most commonly used component, which applies CSS classes at different stages:styles.css
Transition lifecycle
- Enter
- Exit
Applied when component enters:
{classNames}-enter- Initial state{classNames}-enter-active- Active transition{classNames}-enter-done- Completed
Key features
CSS-based
Uses CSS transitions and animations for actual styling, keeping JavaScript minimal.
Lifecycle hooks
Provides callbacks for transition stages: onEnter, onEntering, onEntered, onExit, onExiting, onExited.
TransitionGroup
Automatically manages transitions for lists of elements.
Lightweight
Small footprint focused solely on managing transition states.
TransitionGroup for lists
Manage transitions for dynamic lists:JavaScript-based transitions
Use the baseTransition component for JavaScript animations:
Common transition patterns
Slide in from side
Scale and fade
When to use it
CSS-first approach
CSS-first approach
Perfect when you prefer writing animations in CSS and just need JavaScript to manage transition timing.
Simple enter/exit transitions
Simple enter/exit transitions
Ideal for basic component mount/unmount animations without complex gesture support.
List animations
List animations
Great for animating items being added or removed from lists with TransitionGroup.
Minimal JavaScript
Minimal JavaScript
Best when you want to keep animation logic in CSS and minimize JavaScript bundle size.
Legacy projects
Legacy projects
Commonly used in older React codebases. Consider Framer Motion for new projects.
Comparison with other libraries
- vs Framer Motion
- vs React Spring
React Transition Group:
- Lower level, more manual control
- CSS-based animations
- Smaller bundle size
- No built-in gesture support
- Higher level, more features
- JavaScript-based animations
- Built-in gestures and layout animations
- More intuitive API
Migration tips
If you’re using React Transition Group and want to modernize:Learn more
Transition examples
See transition patterns in action
Official docs
Visit React Transition Group docs