Fade List Items - React-transition-group Typing CST Test
Loading…
Fade List Items — React-transition-group Code
Fades items in a list
# react_transition_group/demo/App5.jsx
import React, { useState } from 'react'
import { TransitionGroup, CSSTransition } from 'react-transition-group'
import './styles.css'
function App() {
const [items, setItems] = useState([])
return (
<div>
<button onClick={() => setItems([...items, `Item ${items.length+1}`])}>Add Item</button>
<TransitionGroup>
{items.map(item => (
<CSSTransition key={item} timeout={300} classNames="fade">
<div className="list-item">{item}</div>
</CSSTransition>
))}
</TransitionGroup>
</div>
)
}
export default AppReact-transition-group Language Guide
React Transition Group (RTG) is a lightweight animation utility for React that enables transitions when components enter, exit, or change state. It provides simple APIs such as CSSTransition, Transition, SwitchTransition, and TransitionGroup to orchestrate animations without dictating animation styles or mechanics.
Primary Use Cases
- ▸Page transitions
- ▸List item animations
- ▸Modal, drawer, and dropdown transitions
- ▸Button and small UI state animations
- ▸Mount/unmount controlled effects
Notable Features
- ▸Declarative enter/exit transitions
- ▸Integration with CSS animations or JS-based animations
- ▸TransitionGroup for list animation
- ▸SwitchTransition for swapping components
- ▸Hook-like lifecycle callbacks for animations
Origin & Creator
React Transition Group was originally developed by the React community as part of React addons, later split into its own standalone package maintained by the React team and open-source contributors.
Industrial Note
RTG is widely used in UI-heavy React apps, dashboards, modals, dropdowns, list animations, route transitions, marketing pages, and any place requiring controlled mount/unmount animations.