From 8086003321fd5e46cd25cef973ba1d62b20e8e1e Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 10 Dec 2021 18:33:47 +0100 Subject: [PATCH] [Perf] Animated Sticker: Avoid redundant data change on first render (#1576) --- src/components/common/AnimatedSticker.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/common/AnimatedSticker.tsx b/src/components/common/AnimatedSticker.tsx index e6ffe5e6..49cc6f90 100644 --- a/src/components/common/AnimatedSticker.tsx +++ b/src/components/common/AnimatedSticker.tsx @@ -60,6 +60,7 @@ const AnimatedSticker: FC = ({ const container = useRef(null); const wasPlaying = useRef(false); const isFrozen = useRef(false); + const isFirstRender = useRef(true); const playRef = useRef(); playRef.current = play; @@ -194,8 +195,12 @@ const AnimatedSticker: FC = ({ useEffect(() => { if (animation) { - animation.changeData(animationData); - playAnimation(); + if (isFirstRender.current) { + isFirstRender.current = false; + } else { + animation.changeData(animationData); + playAnimation(); + } } }, [playAnimation, animation, animationData]);