1. Home
  2. /
  3. Preact-motion
  4. /
  5. Scale Up

Scale Up - Preact-motion Typing CST Test

Loading…

Scale Up — Preact-motion Code

Scales up a div from 0.5 to 1

# preact_motion/demo/App2.jsx
import { h } from 'preact'
import { Motion } from 'preact-motion'

export default function App() {
	return (
		<Motion defaultStyle={{ scale: 0.5 }} style={{ scale: 1 }}>
		{style => (
		<div style={{ width: 100, height: 100, background: 'green', transform: `scale(${style.scale})` }} />
		)}
		</Motion>
	)
}

Preact-motion Language Guide

Preact Motion is a lightweight animation library for Preact that provides physics-based, spring-driven animations similar to React-Motion. It brings declarative motion primitives such as springs, presets, transitions, and dynamic interpolation tailored for Preact’s small footprint and high performance.

Primary Use Cases

  • ▸Smooth, spring-based UI animations
  • ▸Element transitions without CSS keyframes
  • ▸Animated toggles and switches
  • ▸Layout-based motion between states
  • ▸Declarative dynamic value interpolation

Notable Features

  • ▸Physics-based springs
  • ▸Declarative Motion component
  • ▸StaggeredMotion for chained animations
  • ▸TransitionMotion for dynamic lists
  • ▸Automatic value interpolation

Origin & Creator

Preact Motion was inspired by React-Motion and built by Preact community members to provide a native physics-based animation library optimized for Preact’s small size.

Industrial Note

Highly relevant for ultra-lightweight dashboards, embedded UIs, IoT interfaces, static sites, WASM/Preact projects, and performance-critical mobile web apps where bundle size must remain extremely small.

Quick Explain

  • ▸Uses spring physics for natural movement.
  • ▸Designed specifically for Preact’s lightweight component model.
  • ▸Declarative motion components like Motion, StaggeredMotion, and TransitionMotion.
  • ▸Automatically interpolates animated values.
  • ▸Great for smooth UI animations without heavy dependencies.

Core Features

  • ▸Motion - animate single style object
  • ▸StaggeredMotion - sequential motion
  • ▸TransitionMotion - animate mounting lists
  • ▸Spring - physics engine wrapper
  • ▸Presets - gentle, wobbly, stiff springs

Learning Path

  • ▸Learn Motion basics
  • ▸Understand spring physics
  • ▸Build toggle-based animations
  • ▸Use StaggeredMotion
  • ▸Master TransitionMotion for lists

Practical Examples

  • ▸Spring-based fade-in box
  • ▸Expand/collapse card
  • ▸Follow-the-mouse spring effect
  • ▸Animating list additions/removals
  • ▸Staggered menu item entrances

Comparisons

  • ▸Preact Motion vs React-Motion: nearly identical API, Preact-optimized.
  • ▸Preact Motion vs Framer Motion: PM is lighter, FM has more features.
  • ▸Preact Motion vs React Spring: PM simpler, smaller.
  • ▸Preact Motion vs CSS: PM allows physics-based interpolation.
  • ▸Preact Motion vs GSAP: GSAP for timelines, PM for UI springs.

Strengths

  • ▸Very lightweight compared to Framer Motion or React Spring
  • ▸Natural spring physics
  • ▸Perfect for micro-interactions
  • ▸Minimal API surface - easy to learn
  • ▸Optimized for Preact performance

Limitations

  • ▸Not a full animation engine (no timeline or gestures)
  • ▸Less feature-rich than React Spring or Framer Motion
  • ▸Limited third-party ecosystem
  • ▸Requires Preact - not directly usable in React
  • ▸Cannot handle complex animation choreography

When NOT to Use

  • ▸Highly choreographed sequences
  • ▸Full gesture-driven apps
  • ▸Heavy SVG animations
  • ▸3D animations
  • ▸Complex timelines

Cheat Sheet

  • ▸import { Motion, spring } from 'preact-motion'
  • ▸spring(100, { stiffness: 120 })
  • ▸<Motion style={{ x: spring(0) }}>{style => ...}</Motion>
  • ▸Use TransitionMotion for lists
  • ▸Presets: presets.gentle / presets.wobbly / presets.stiff

FAQ

  • ▸Does it support timelines? -> No.
  • ▸Is it lightweight? -> Extremely.
  • ▸Does it replace CSS transitions? -> For springs, yes.
  • ▸Does it work in React? -> No, only Preact.
  • ▸Does it handle enter/exit? -> Yes via TransitionMotion.

30-Day Skill Plan

  • ▸Week 1: springs + Motion
  • ▸Week 2: gestures + interactions
  • ▸Week 3: multi-element layouts
  • ▸Week 4: transitioning lists
  • ▸Week 5: production-level motion system

Final Summary

  • ▸Preact Motion brings physics-based animations to Preact.
  • ▸It provides Motion, StaggeredMotion, and TransitionMotion components.
  • ▸Extremely lightweight, ideal for performance-sensitive apps.
  • ▸Perfect for UI micro-interactions and smooth spring effects.
  • ▸A minimal but powerful animation solution.

Project Structure

  • ▸components/ - animated UI parts
  • ▸motion/ - spring presets
  • ▸styles/ - optional CSS
  • ▸hooks/ - interaction handlers
  • ▸App.jsx - root animations

Monetization

  • ▸Lightweight UI component kits
  • ▸Interactive embedded widgets
  • ▸Premium templates for Preact
  • ▸Animated SaaS dashboards
  • ▸Motion-first landing pages

Productivity Tips

  • ▸Use presets for reusable springs
  • ▸Combine with Preact Signals
  • ▸Tune stiffness/damping carefully
  • ▸Preview animations early
  • ▸Keep motion logic centralized

Basic Concepts

  • ▸Springs: natural motion vs linear
  • ▸Motion component controls interpolation
  • ▸StaggeredMotion chains multiple animations
  • ▸TransitionMotion handles dynamic lists
  • ▸Presets for common spring behaviors

Official Docs

  • ▸https://github.com/developit/preact-motion
  • ▸https://preactjs.com/guide

More Preact-motion Typing Exercises

Simple Fade InFade + ScaleSlide RightSlide UpRotateScale + RotateFade + Slide RightFade + Slide UpBounce Scale

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher