惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
F
Fortinet All Blogs
J
Java Code Geeks
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
M
MIT News - Artificial intelligence
腾讯CDC
Last Week in AI
Last Week in AI
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
Microsoft Security Blog
Microsoft Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
博客园 - 叶小钗
Recent Announcements
Recent Announcements
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
人人都是产品经理
人人都是产品经理
L
LangChain Blog
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How to Use Lottie Animations in React (2025 Guide)
Fazal Shah · 2026-05-31 · via DEV Community

Fazal Shah

Lottie animations in React are straightforward once you know the two main libraries. Here's the complete setup — from installing the package to controlling playback with hooks.

Option 1: @lottiefiles/dotlottie-react (Recommended)

This is the modern approach. Supports both .json and .lottie files.

npm install @lottiefiles/dotlottie-react

Enter fullscreen mode Exit fullscreen mode

Basic usage:

import { DotLottieReact } from '@lottiefiles/dotlottie-react';

export default function App() {
  return (
    <DotLottieReact
      src="/animation.json"
      loop
      autoplay
      style={{ width: 300, height: 300 }}
    />
  );
}

Enter fullscreen mode Exit fullscreen mode

The src can point to a local file in your public/ folder or a remote URL.

Option 2: lottie-web + react-lottie

The older approach. Still widely used.

npm install react-lottie

Enter fullscreen mode Exit fullscreen mode

import Lottie from 'react-lottie';
import animationData from './animation.json';

export default function App() {
  const options = {
    loop: true,
    autoplay: true,
    animationData,
  };
  return <Lottie options={options} height={300} width={300} />;
}

Enter fullscreen mode Exit fullscreen mode

Controlling Playback

With dotlottie-react, use the dotLottie ref:

import { DotLottieReact } from '@lottiefiles/dotlottie-react';
import { useState } from 'react';

export default function ControlledAnimation() {
  const [dotLottie, setDotLottie] = useState(null);
  return (
    <div>
      <DotLottieReact
        src="/animation.json"
        dotLottieRefCallback={setDotLottie}
        style={{ width: 200, height: 200 }}
      />
      <button onClick={() => dotLottie?.play()}>Play</button>
      <button onClick={() => dotLottie?.pause()}>Pause</button>
      <button onClick={() => dotLottie?.stop()}>Stop</button>
    </div>
  );
}

Enter fullscreen mode Exit fullscreen mode

Trigger on Hover

export default function HoverAnimation() {
  const [dotLottie, setDotLottie] = useState(null);
  return (
    <div
      onMouseEnter={() => dotLottie?.play()}
      onMouseLeave={() => dotLottie?.stop()}
    >
      <DotLottieReact
        src="/animation.json"
        dotLottieRefCallback={setDotLottie}
        loop={false}
        style={{ width: 100, height: 100 }}
      />
    </div>
  );
}

Enter fullscreen mode Exit fullscreen mode

Where to Get Free Lottie JSON Files

IconKing has 500+ free Lottie animations — UI icons, loaders, social media, flags, illustrations. No signup required.

Use the Lottie preview tool to check timing before integrating. The editor lets you change colors and speed in-browser.

Converting to Other Formats

When you need the same animation in GIF (for email), MP4, or WebM:

All free at iconking.net.

Performance Tips

SVG renderer for small animations. For icons and UI elements, SVG is crisper than canvas at small sizes.

Bundle size. @lottiefiles/dotlottie-react is ~100KB. lottie-web is ~500KB. For production, dotLottie is the better choice.


Browse free animations at iconking.net/all-assets, preview at iconking.net/preview, drop the JSON in your public/ folder — done in under 5 minutes.