Skip to content

🎥 Make videos programmatically with React

throw error if lottie fails to load

Jonny Burgerc75fe3409a1f
diff --git a/packages/example/src/Lottie/Halloween/Balloons.tsx b/packages/example/src/Lottie/Halloween/Balloons.tsx
index 2854edfc96..e1f2317f06 100644
--- a/packages/example/src/Lottie/Halloween/Balloons.tsx
+++ b/packages/example/src/Lottie/Halloween/Balloons.tsx
@@ -21,8 +21,13 @@ const Balloons = () => {
[0, 1, 1, 0]
);
+ const [error, setError] = useState<Error | null>(null);
const [handle] = useState(() => delayRender('Loading Lottie animation'));
+ if (error) {
+ throw error;
+ }
+
const [animationData, setAnimationData] =
useState<LottieAnimationData | null>(null);
@@ -35,6 +40,7 @@ const Balloons = () => {
continueRender(handle);
})
.catch((err) => {
+ setError(err);
console.log('Animation failed to load', err);
});
}, [handle]);
diff --git a/packages/example/src/Lottie/Loader/index.tsx b/packages/example/src/Lottie/Loader/index.tsx
index 578e5364d3..33c1573e76 100644
--- a/packages/example/src/Lottie/Loader/index.tsx
+++ b/packages/example/src/Lottie/Loader/index.tsx
@@ -12,6 +12,12 @@ const LottieLoader = () => {
const frame = useCurrentFrame();
const [handle] = useState(() => delayRender('Loading Lottie animation'));
+ const [error, setError] = useState<Error | null>(null);
+
+ if (error) {
+ throw error;
+ }
+
const [animationData, setAnimationData] =
useState<LottieAnimationData | null>(null);
@@ -24,6 +30,7 @@ const LottieLoader = () => {
continueRender(handle);
})
.catch((err) => {
+ setError(err);
console.log('Animation failed to load', err);
});
}, [handle]);