Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

React
  • One Request, Two Answers: the Same Post as an HTML Page and as JSON
  • A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
  • How a Web Page Works: HTML Tags, Elements and Attributes
  • Semantic HTML: header, nav, main, aside and footer as Page Landmarks
  • HTML Forms: Labels, Names, Input Types and Where the Data Goes (GET vs POST)
  • CSS Basics: Selectors, Which Rule Wins, and the Box Model
  • CSS Flexbox vs Grid: A Nav Bar, a Card Row and a Dashboard
  • Responsive CSS: Viewport, Mobile-First Media Queries, clamp() and Dark Mode with Tokens
  • JavaScript for People Who Already Code: Syntax, Modules and Five Surprises
  • JavaScript Arrays the Functional Way: map, filter, reduce, find, sort and Object.entries
  • Async JavaScript: Promises, async/await, fetch and Promise.all
  • JavaScript in the Page: the DOM, querySelector and Events
  • npm, package.json and Vite: What npm install Fetches and How Vite Serves and Builds Your Page
  • TypeScript Essentials: Types Checked, Then Erased (Interfaces, Unions, Generics)
  • Why React, JSX and Components: The Page as a Function of Data
  • React Props and Composition: Data Down, Calls Up, Children in the Slot
  • Routing With React Router: One Page, Many Addresses
  • React Component Tests With Vitest and Testing Library: Test What the User Sees
  • End-to-End Tests for a React App With Playwright: A Full Dress Rehearsal
  • Why AI-Built Websites All Look the Same, and Four Levels That Fix It
  • Visual Hierarchy, Spacing and the 8-Point Grid: Tell the Eye What to Read First
  • Colour, Contrast and Dark Palettes: 60-30-10, Semantic Tokens and Ratios You Can Compute
  • Typography That Sells: Type Scale, Line Length and Free Font Pairings
  • The UI Element Catalogue: Buttons to Toasts, Their Jobs, States and shadcn/ui Names
  • Design Tokens: Primitive and Semantic Tokens, from Figma to CSS to Tailwind
  • Tailwind CSS 4 in React: Utility Classes, Responsive Prefixes, Hover and Dark Mode
  • shadcn/ui in React: Components You Own, Edit and Commit
  • Design Tokens to a Tailwind Theme: Light and Dark Mode with @theme inline
  • Motion in React: Entrance, Hover, Exit and Layout Animations
  • A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table
  • Accessibility in Practice: Dialogs, Menus and the Keyboard in React
  • Reference-Driven Design: Extract a DESIGN.md From a Site You Admire and Build From It
  • Components, Variants and Variables: One Design System in Figma and in CSS
  • Figma MCP Server: Build a React Component From a Frame, Then Write It Back
  • Claude Design: From a Brief to a Clickable Prototype, Then Hand It Off to Claude Code
  • Critiquing AI-Generated UI: Six Checks for Every Screen
  • The AI Design Landscape: Prompt to UI, Prompt to App, and Design to Code
  • Your Brand Rules Folder: One Folder Every AI-Built Page Follows
  • The Best-Practice UI Prompt: Plain Sentences That Beat the Average AI Page
  • UI Ideas From Figma Make, Google Stitch and ChatGPT: One Prompt, Three Designs
  • Google Stitch From a Sketch or Screenshot: Show the Layout, Say What to Keep
  • Stitch to Figma to Code: Turn a Stitch Screen Into Code That Uses Your Tokens
  • Figma Make: Prompt to Prototype With a Four-Part Prompt
  • Upgrade a Dated UI From One Screenshot (or a Reference Image)
  • States and Feedback: Make Every Click Get an Answer
  • A Design-Loop Skill: Claude Screenshots, Scores and Fixes Its Own UI
  • Copy Without the AI Tells: A Copy Pass on a Landing Page
  • React State, Events, Lists and Conditional Rendering: Follow One Click
  • React useEffect: When It Runs, What Cleanup Is For, and When You Don't Need One
  • Lifting State Up, Refs and React DevTools: Put State Where It Is Needed
  • Forms and Actions in React 19: Controlled Inputs, Form Actions, useActionState and useFormStatus
  • React Context and Custom Hooks: Share One Value, Reuse the Logic
  • Server State With TanStack Query: One Key, One Request, One Cache
  • Mutations and Optimistic Updates in TanStack Query: Change Data, Then Tell the Cache
  • Generate TypeScript Types, Query Hooks and Zod From an OpenAPI Spec With Orval
  • A Mock Backend in the Browser With Mock Service Worker, Generated From the Spec
  • A React Client for a FastAPI API: The CORS Wall, CORSMiddleware and the Vite Proxy
  • Forms With React Hook Form and Zod: The API's Rules in the Browser, the Server's Errors Under the Field
  • JWT Auth in a React Client With a FastAPI Backend: Log In, Carry the Token, Let the Server Decide
  1. Blog
  2. /
  3. React
  4. /
  5. Fundamentals

Motion in React: Entrance, Hover, Exit and Layout Animations

Small animations that make an app feel premium, with the motion package: a staggered entrance, a springy button, a list row that slides out while the others glide up, a reduced-motion setting, and the missing AnimatePresence bug.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Fundamentals

What you will learn

  • Animate an entrance with initial, animate and a staggered delay
  • Add hover and tap micro-interactions with whileHover and whileTap
  • Animate a removed list item with exit, AnimatePresence and layout
  • Respect the reduce motion setting with MotionConfig

Before you start

  • React components and props
  • React useState

A door that opens smoothly tells you where to go. A wall that changes instantly leaves you confused.

Take a list of tasks and remove "Email Jack". With no motion, the row just vanishes, the list jumps up, and you think: wait, what happened? With motion, the row slides away and fades out, and the other rows glide up to close the gap. Same result, but your eyes followed what happened. Motion is feedback. It shows the user what just changed.

One package, four jobs

npm install motion

The package is called motion, and you import from motion/react. Older tutorials use the name framer-motion. That is the old name.

JobProps
Entranceinitial, animate
HoverwhileHover, whileTap
Exitexit (inside AnimatePresence)
Layoutlayout: neighbours glide to their new places

There are no timelines and no separate animation files. Just props. A plain div becomes motion.div, a list item becomes motion.li, a button becomes motion.button.

Entrance: fade and rise

import { motion } from 'motion/react'

const names = [
  'Write report', 'Email Jack', 'Book flights',
]
type Props = { run: number }

export default function Entrance({ run }: Props) {
  return names.map((name, i) => (
    <motion.div
      key={run + name}
      className="item"
      initial={{ opacity: 0, y: 24 }}
      animate={{ opacity: 1, y: 0 }}
      transition={{ duration: 0.4, delay: i * 0.1 }}
    >
      {name}
    </motion.div>
  ))
}

For each of the three task names you return a motion.div. initial is opacity: 0, y: 24, so it starts invisible and a little below. animate is opacity: 1, y: 0, so it ends fully visible, in place. The transition lasts 0.4 seconds, and the delay is i * 0.1, so every item starts a little later than the one before.

Four frames of the Entrance card. Frame 1: only a faint Write report, low in the card. Frame 2: Write report in place, Email Jack fading in below it. Frame 3: Book flights is rising into place. Frame 4: all three items settled.
Frames from the running page, left to right and top to bottom: hidden and low, rising, nearly there, settled.

That small stagger is what makes it feel premium. (The key includes run, so the Replay button in the demo remounts the items and plays it again.)

Hover: the button answers

import { motion } from 'motion/react'

export default function SaveButton() {
  return (
    <motion.button
      whileHover={{ scale: 1.08 }}
      whileTap={{ scale: 0.95 }}
      transition={{ type: 'spring', stiffness: 400 }}
    >
      Save changes
    </motion.button>
  )
}

whileHover scales the button to 1.08 while the pointer is on it. whileTap scales it to 0.95 while you press. The transition is a spring with stiffness 400, so it feels bouncy rather than robotic.

Three frames of the Save changes button: resting, slightly larger on hover, and slightly smaller while pressed.
Resting, hover (grows to 1.08), pressed (shrinks to 0.95).

You never wrote a hover handler or any state for this. Motion does that work. That is a micro-interaction: a tiny answer to what the user does.

Exit: leave smoothly

This is where people get stuck.

import { useState } from 'react'
import { AnimatePresence, motion } from 'motion/react'

const start = ['Write report', 'Email Jack', 'Book flights']

export default function Tasks() {
  const [items, setItems] = useState(start)
  const remove = (n: string) =>
    setItems(items.filter((x) => x !== n))
  return (
    <ul>
      <AnimatePresence mode="popLayout">
        {items.map((name) => (
          <motion.li
            key={name}
            layout
            exit={{ opacity: 0, x: 80 }}
            onClick={() => remove(name)}
          >
            {name}
          </motion.li>
        ))}
      </AnimatePresence>
    </ul>
  )
}

The items are in state, and clicking a row calls remove, which filters it out of the array. Each row is a motion.li with the layout prop and an exit of opacity: 0, x: 80. And the important part: the whole list is wrapped in AnimatePresence. Why? Because when React removes an element, it is gone immediately. AnimatePresence keeps the row on screen long enough to play its exit.

Four frames of the task list. Frame 1: Write report, Email Jack and Book flights. Frame 2: Book flights has moved up while Email Jack slides right and fades over it. Frame 3: Email Jack is a faint ghost to the right. Frame 4: Write report and Book flights, settled.
Click Email Jack: it slides right and fades, and because of layout, Book flights glides up to close the gap.

No jump anywhere. The gap closing is layout doing its job, with no extra code from you.

Reduced motion: respect the setting

Some people get dizzy from movement, so their operating system has a reduce motion setting. In main.tsx, the app is wrapped in MotionConfig:

import { createRoot } from 'react-dom/client'
import { MotionConfig } from 'motion/react'
import './index.css'
import App from './App'

createRoot(document.getElementById('root')!).render(
  <MotionConfig reducedMotion="user">
    <App />
  </MotionConfig>,
)

With reducedMotion="user", Motion follows that system setting.

Two frames of the Entrance card at the same moment. Left, normal: the fading items are still a little below their final place. Right, reduce motion on: the items fade in already in place.
Left: normal, the items rise as they fade in. Right: reduce motion on, they only fade.

Fading is gentle, so it stays. Movement like the rise is skipped. One line, and this is part of doing animation properly, not an extra.

Break it: no AnimatePresence, no exit

Here is the same list without the wrapper. The exit prop is still there:

import { useState } from 'react'
import { motion } from 'motion/react'

const start = ['Write report', 'Email Jack', 'Book flights']

// BREAK IT: the same list without <AnimatePresence>
export default function TasksNoExit() {
  const [items, setItems] = useState(start)
  const remove = (n: string) =>
    setItems(items.filter((x) => x !== n))
  return (
    <ul>
      {items.map((name) => (
        <motion.li
          key={name}
          layout
          exit={{ opacity: 0, x: 80 }}
          onClick={() => remove(name)}
        >
          {name}
        </motion.li>
      ))}
    </ul>
  )
}

Click a row and it is just gone at once. The code compiles, it runs, there is no error. There is simply no exit animation, which is why this is so easy to miss. It is not really a bug, it is a missing wrapper: React removes the row before exit can play. Wrap the list in AnimatePresence.

Common mistakes

  • Importing from framer-motion in a new project. The package is motion, imported from motion/react.
  • exit without AnimatePresence. Nothing happens and nothing complains.
  • Ignoring reduce motion. One MotionConfig at the root covers the whole app.

Recap

JobWhat to write
Entranceinitial + animate, stagger with delay: i * 0.1
HoverwhileHover + whileTap, spring transition
Exitexit inside AnimatePresence
Layoutlayout on the items that should glide
Respect users<MotionConfig reducedMotion="user">

Motion is a foundation. AI can generate fancier animations, and you decide what feels right. Try it yourself: give the entrance items an exit too, wrap them in AnimatePresence, and see what happens when you press Replay.

Keep going in React · 29 of 59

Previous
Design Tokens to a Tailwind Theme: Light and Dark Mode with @theme inline
Next post
A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Related posts

One Request, Two Answers: the Same Post as an HTML Page and as JSON

Ask a Django blog for the same post twice: once as a 12,731-byte HTML page built by a template, once as 2,976 bytes of JSON built by a serializer. Compare the headers, see who builds the page, and why the server still owns every write.

A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx

Make a blog design from a prompt in Figma Make, download src.zip, unzip it with Python's zipfile module, and read the two files that matter: App.tsx with its selectedPost state and BlogCard.tsx with its props.

How a Web Page Works: HTML Tags, Elements and Attributes

A web page is a text file full of labelled pieces. Learn tags, attributes and nesting with three tiny pages, and see what breaks when an attribute or a closing tag is wrong.

Semantic HTML: header, nav, main, aside and footer as Page Landmarks

The same page written as div soup and with semantic tags looks identical, but only one gives screen readers and search engines landmarks and an outline. Plus tables, div, span and the one-main rule.

On this page

  • One package, four jobs
  • Entrance: fade and rise
  • Hover: the button answers
  • Exit: leave smoothly
  • Reduced motion: respect the setting
  • Break it: no AnimatePresence, no exit
  • Common mistakes
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.