name: lottie description: Embedding Lottie animations in Remotion. metadata:
First, the @remotion/lottie package needs to be installed.
If it is not, use the following command:
npx remotion add @remotion/lottie # If project uses npm bunx remotion add @remotion/lottie # If project uses bun yarn remotion add @remotion/lottie # If project uses yarn pnpm exec remotion add @remotion/lottie # If project uses pnpm
To import a Lottie animation:
delayRender() and continueRender()Lottie component from the @remotion/lottie packageimport { Lottie, LottieAnimationData } from "@remotion/lottie";
import { useEffect, useState } from "react";
import { cancelRender, continueRender, delayRender } from "remotion";
export const MyAnimation = () => {
const [handle] = useState(() => delayRender("Loading Lottie animation"));
const [animationData, setAnimationData] =
useState<LottieAnimationData | null>(null);
useEffect(() => {
fetch("https://assets4.lottiefiles.com/packages/lf20_zyquagfl.json")
.then((data) => data.json())
.then((json) => {
setAnimationData(json);
continueRender(handle);
})
.catch((err) => {
cancelRender(err);
});
}, [handle]);
if (!animationData) {
return null;
}
return <Lottie animationData={animationData} />;
};
Lottie supports the style prop to allow styles and animations:
return (
<Lottie animationData={animationData} style={{ width: 400, height: 400 }} />
);