From 99e86905802df2284a153221f223e64f8b48f2ef Mon Sep 17 00:00:00 2001 From: arvndvv Date: Tue, 10 Sep 2024 10:29:23 +0530 Subject: [PATCH] fix: settimeout trying to scroll when element is undefined --- src/components/timeline/timeline.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/timeline/timeline.tsx b/src/components/timeline/timeline.tsx index acd624c2f..9a9d40a17 100644 --- a/src/components/timeline/timeline.tsx +++ b/src/components/timeline/timeline.tsx @@ -207,9 +207,11 @@ const Timeline: React.FunctionComponent = ( const { width: contentWidth, left: contentLeft } = contentRect; setTimeout(() => { const ele = horizontalContentRef.current as HTMLElement; - ele.style.scrollBehavior = 'smooth'; - ele.scrollLeft += - cardLeft - contentLeft + cardWidth / 2 - contentWidth / 2; + if(ele){ + ele.style.scrollBehavior = 'smooth'; + ele.scrollLeft += + cardLeft - contentLeft + cardWidth / 2 - contentWidth / 2; + } }, 100); } }