Skip to content

🎥 Make videos programmatically with React

just use one useEffect()

Jonny Burger5d7a5326eba8
diff --git a/packages/example/src/Lottie/Cybertruck/index.tsx b/packages/example/src/Lottie/Cybertruck/index.tsx
index 92c24a7226..31e1ae95a5 100644
--- a/packages/example/src/Lottie/Cybertruck/index.tsx
+++ b/packages/example/src/Lottie/Cybertruck/index.tsx
@@ -1,4 +1,4 @@
-import {Lottie} from '@remotion/lottie';
+import {Lottie, LottieAnimationData} from '@remotion/lottie';
import {useEffect, useState} from 'react';
import {
AbsoluteFill,
@@ -9,21 +9,19 @@ import {
const LottieCybertruck = () => {
const {height, width} = useVideoConfig();
- const [animationData, setAnimationData] = useState(null);
+ const [animationData, setAnimationData] =
+ useState<LottieAnimationData | null>(null);
const [handle] = useState(delayRender);
useEffect(() => {
// Credits: https://lottiefiles.com/11643-tesla-cybertruck
fetch('https://assets2.lottiefiles.com/packages/lf20_RqpTFh.json')
.then((res) => res.json())
- .then(setAnimationData);
- }, []);
-
- useEffect(() => {
- if (animationData) {
- continueRender(handle);
- }
- }, [animationData, handle]);
+ .then((data) => {
+ setAnimationData(data);
+ continueRender(handle);
+ });
+ }, [handle]);
if (!animationData) {
return null;