1. Home
  2. /
  3. React-transition-group
  4. /
  5. Horizontal Slide

Horizontal Slide - React-transition-group Typing CST Test

Loading…

Horizontal Slide — React-transition-group Code

Slides horizontally in/out

# react_transition_group/demo/App4.jsx
import React, { useState } from 'react'
import { CSSTransition } from 'react-transition-group'
import './styles.css'

function App() {
	const [show, setShow] = useState(false)
	return (
		<div>
		<button onClick={() => setShow(!show)}>Toggle Slide</button>
		<CSSTransition in={show} timeout={350} classNames="slideH" unmountOnExit>
		<div className="box">Horizontal Slide</div>
		</CSSTransition>
		</div>
	)
}

export default App

React-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.

Quick Explain

  • ▸RTG manages component mount/unmount transitions cleanly.
  • ▸It works with any animation approach-CSS, JS, or external libraries.
  • ▸Provides lifecycle hooks for entering/exiting states.
  • ▸Allows coordinated animations for lists and dynamic UI elements.
  • ▸Lightweight and minimal, focusing only on transition state control.

Core Features

  • ▸Transition - low-level transition state manager
  • ▸CSSTransition - class-based CSS animations
  • ▸TransitionGroup - orchestrates multiple child transitions
  • ▸SwitchTransition - handles in-place component transitions
  • ▸Lifecycle states: entering, entered, exiting, exited

Learning Path

  • ▸Learn CSSTransition basics
  • ▸Understand Transition lifecycle states
  • ▸Animate mount/unmount of components
  • ▸Use TransitionGroup for lists
  • ▸Use SwitchTransition for dynamic changes

Practical Examples

  • ▸Fade in/out a component
  • ▸Slide-down menu transitions
  • ▸Modal open/close animation
  • ▸Animate list items on add/remove
  • ▸Switching pages or tabs with transitions

Comparisons

  • ▸RTG vs Framer Motion: RTG controls lifecycle, FM controls animation physics.
  • ▸RTG vs GSAP: RTG manages presence, GSAP manages animation logic.
  • ▸RTG vs React Spring: Spring handles physics animations; RTG doesn’t.
  • ▸RTG vs CSS only: RTG enables mount/unmount transitions.
  • ▸RTG vs Anime.js: different animation responsibilities.

Strengths

  • ▸Very lightweight (~9kb)
  • ▸Flexible - works with CSS or JS animation libraries
  • ▸Great for mount/unmount animation control
  • ▸Good compatibility with existing React projects
  • ▸Lifecycle hooks offer fine-grained control

Limitations

  • ▸Not a full animation engine like Framer Motion or GSAP
  • ▸No built-in physics or gestures
  • ▸More manual work than dedicated animation libraries
  • ▸Requires careful class naming for CSSTransition
  • ▸Limited support for complex timeline-based animations

When NOT to Use

  • ▸Complex motion design with physics
  • ▸High-performance animation-heavy experiences
  • ▸3D animations or timeline sequences
  • ▸Game-like UI animations
  • ▸SVG animation choreography

Cheat Sheet

  • ▸import { CSSTransition } from 'react-transition-group';
  • ▸timeout={300} - animation duration
  • ▸classNames='fade' - CSS class prefix
  • ▸<TransitionGroup></TransitionGroup>
  • ▸<SwitchTransition mode='out-in'></SwitchTransition>

FAQ

  • ▸Does RTG animate by itself? -> No, you provide the CSS/JS animations.
  • ▸Is it large? -> No, very small and lightweight.
  • ▸Does it work with React Router? -> Yes, commonly used for route animations.
  • ▸Can it animate lists? -> Yes, via TransitionGroup.
  • ▸Does it work with CSS or JS? -> Both.

30-Day Skill Plan

  • ▸Week 1: Simple transitions with CSS
  • ▸Week 2: Handling modals and dropdowns
  • ▸Week 3: Advanced Transition callbacks
  • ▸Week 4: List animations with TransitionGroup
  • ▸Week 5: Full animation system for an app

Final Summary

  • ▸RTG is a lightweight transition lifecycle manager for React.
  • ▸Lets you animate components as they mount/unmount.
  • ▸Works with any CSS or JS animation method.
  • ▸Ideal for UI transitions like modals, dropdowns, and lists.
  • ▸Perfect for React apps needing simple but reliable animations.

Project Structure

  • ▸components/ - UI components using RTG
  • ▸animations/ - CSS or JS animation rules
  • ▸pages/ - animated route pages
  • ▸utils/ - helpers for timing and transition logic
  • ▸App.js - root animation wrappers

Monetization

  • ▸Used in UI kits and template sales
  • ▸Animations for SaaS dashboards
  • ▸Component libraries
  • ▸Premium animated landing pages
  • ▸Interactive product demos

Productivity Tips

  • ▸Use TransitionGroup for list automation
  • ▸Sync timeout with CSS animations
  • ▸Use SwitchTransition for tab/page swapping
  • ▸Break animations into reusable CSS classes
  • ▸Preview animations frequently

Basic Concepts

  • ▸Transition states: entering/entered/exiting/exited
  • ▸Timeouts define animation duration
  • ▸CSSTransition applies classNames automatically
  • ▸TransitionGroup manages a collection of items
  • ▸SwitchTransition handles one-at-a-time replacements

Official Docs

  • ▸https://reactcommunity.org/react-transition-group/
  • ▸https://github.com/reactjs/react-transition-group

More React-transition-group Typing Exercises

Fade ToggleSlide DownFade + ScaleFade List ItemsZoom On MountFade + Slide UpFade + Slide DownFade with DelayFade List Removal

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher