build: lazy load lottie-web (#1622)

This commit is contained in:
Himself65 2023-03-20 02:55:09 -05:00 committed by GitHub
parent cf3230c1ff
commit 45761f0250
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,9 @@
import lottie from 'lottie-web';
import { atom, useAtomValue } from 'jotai';
import type { FC } from 'react';
import { useEffect, useRef } from 'react';
const lottieAtom = atom(async () => import('lottie-web').then(m => m.default));
type CustomLottieProps = {
options: {
loop?: boolean | number | undefined;
@ -26,6 +28,7 @@ const CustomLottie: FC<CustomLottieProps> = ({
}) => {
const element = useRef<HTMLDivElement>(null);
const lottieInstance = useRef<any>();
const lottie = useAtomValue(lottieAtom);
useEffect(() => {
if (element.current) {
@ -37,7 +40,7 @@ const CustomLottie: FC<CustomLottieProps> = ({
return () => {
lottieInstance.current?.destroy();
};
}, [options]);
}, [lottie, options]);
useEffect(() => {
if (speed) {