From 01638f4dd73df61799bb562b4c102ae8748b2930 Mon Sep 17 00:00:00 2001 From: Hrishikesh Vaipurkar Date: Thu, 21 Nov 2024 11:18:02 +0100 Subject: [PATCH] fix: SW-967 Fixed bad setState call error --- components/HotelReservation/HotelCardListing/index.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/HotelReservation/HotelCardListing/index.tsx b/components/HotelReservation/HotelCardListing/index.tsx index 3e96a6cac..f666c5ba2 100644 --- a/components/HotelReservation/HotelCardListing/index.tsx +++ b/components/HotelReservation/HotelCardListing/index.tsx @@ -73,7 +73,6 @@ export default function HotelCardListing({ const hotels = useMemo(() => { if (activeFilters.length === 0) { - setResultCount(sortedHotels.length) return sortedHotels } @@ -85,9 +84,8 @@ export default function HotelCardListing({ ) ) - setResultCount(filteredHotels.length) return filteredHotels - }, [activeFilters, sortedHotels, setResultCount]) + }, [activeFilters, sortedHotels]) useEffect(() => { const handleScroll = () => { @@ -99,6 +97,10 @@ export default function HotelCardListing({ return () => window.removeEventListener("scroll", handleScroll) }, []) + useEffect(() => { + setResultCount(hotels ? hotels.length : 0) + }, [hotels, setResultCount]) + function scrollToTop() { window.scrollTo({ top: 0, behavior: "smooth" }) }