From dbe5b3f08e9c55584d372bd9bcd967147d87ede8 Mon Sep 17 00:00:00 2001 From: Vibhor Phalke <vibgitcode27@gmail.com> Date: Fri, 13 Oct 2023 23:33:43 +0530 Subject: [PATCH] fix: fixed runtime error that occurs because, classList reading properties of null (#218) * Fixed runtime error that occurs because, classList reading properties of NULL * Fixed runtime error bug. * added optional chain expression --- components/Countdown/countdown.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/components/Countdown/countdown.js b/components/Countdown/countdown.js index f42faf7d..b07c758f 100644 --- a/components/Countdown/countdown.js +++ b/components/Countdown/countdown.js @@ -29,10 +29,14 @@ function Countdowns() { dateRef.current.classList.add('home-title'); setSelectedIndex((prevIndex) => (prevIndex + 1) % dates.length); setTimeout(() => { - locationRef.current.classList.remove('home-title'); - locationRef.current.classList.add('hidden'); - dateRef.current.classList.remove('home-title'); - dateRef.current.classList.add('hidden'); + if(locationRef?.current) { + locationRef.current.classList.remove('home-title'); + locationRef.current.classList.add('hidden'); + } + if(dateRef?.current) { + dateRef.current.classList.remove('home-title'); + dateRef.current.classList.add('hidden'); + } }, 9900); // Element stays visible for 800 milliseconds }, 10000); // Toggle visibility every 1500 milliseconds