From 4ef54ee901b64e6ab62311627b185f5f0299439d Mon Sep 17 00:00:00 2001 From: Michal Hernas Date: Fri, 29 Jan 2021 15:47:02 +0100 Subject: [PATCH] Comparing children using fast equal check instead of just length --- packages/react-gsap/src/Tween.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/react-gsap/src/Tween.tsx b/packages/react-gsap/src/Tween.tsx index 0b82ab0..2156865 100644 --- a/packages/react-gsap/src/Tween.tsx +++ b/packages/react-gsap/src/Tween.tsx @@ -109,11 +109,12 @@ class Tween extends React.Component { } = this.props; // if children change create a new tween - // TODO: replace easy length check with fast equal check - if (React.Children.count(prevProps.children) !== React.Children.count(children)) { + const previousChildren = React.Children.map(prevProps.children, (c: any) => c.key); + const currentChildren = React.Children.map(children, (c: any) => c.key); + if (!isEqual(previousChildren, currentChildren)) { this.createTween(); } - + if (disabled) { return; }