Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply best practices for creating programmatic videos with Remotion and React
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/lottie.md
1---2name: lottie3description: Embedding Lottie animations in Remotion.4metadata:5category: Animation6---78# Using Lottie Animations in Remotion910## Prerequisites1112First, the @remotion/lottie package needs to be installed.13If it is not, use the following command:1415```bash16npx remotion add @remotion/lottie # If project uses npm17bunx remotion add @remotion/lottie # If project uses bun18yarn remotion add @remotion/lottie # If project uses yarn19pnpm exec remotion add @remotion/lottie # If project uses pnpm20```2122## Displaying a Lottie file2324To import a Lottie animation:2526- Fetch the Lottie asset27- Wrap the loading process in `delayRender()` and `continueRender()`28- Save the animation data in a state29- Render the Lottie animation using the `Lottie` component from the `@remotion/lottie` package3031```tsx32import { Lottie, LottieAnimationData } from "@remotion/lottie";33import { useEffect, useState } from "react";34import { cancelRender, continueRender, delayRender } from "remotion";3536export const MyAnimation = () => {37const [handle] = useState(() => delayRender("Loading Lottie animation"));3839const [animationData, setAnimationData] =40useState<LottieAnimationData | null>(null);4142useEffect(() => {43fetch("https://assets4.lottiefiles.com/packages/lf20_zyquagfl.json")44.then((data) => data.json())45.then((json) => {46setAnimationData(json);47continueRender(handle);48})49.catch((err) => {50cancelRender(err);51});52}, [handle]);5354if (!animationData) {55return null;56}5758return <Lottie animationData={animationData} />;59};60```6162## Styling and animating6364Lottie supports the `style` prop to allow styles and animations:6566```tsx67return (68<Lottie animationData={animationData} style={{ width: 400, height: 400 }} />69);70```71