From 3b8e574f1d4d752337fe93ec09e78f0a1646d968 Mon Sep 17 00:00:00 2001 From: Lennu Vuolanne Date: Mon, 26 Aug 2024 13:20:31 +0300 Subject: [PATCH] refactor --- components/Carousel.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/Carousel.tsx b/components/Carousel.tsx index 85c5935..bdd981d 100644 --- a/components/Carousel.tsx +++ b/components/Carousel.tsx @@ -22,11 +22,10 @@ const wrappedDistance = (a: number, b: number) => { const setOpacity = (emblaApi: EmblaCarouselType) => { const slideNodes = emblaApi.slideNodes(); - const slidesInView = slideNodes.map((_, index) => index); const currentPosition = emblaApi.scrollProgress(); - slidesInView.forEach((slideIndex) => { + slideNodes.forEach((_, slideIndex) => { const slidePosition = emblaApi.scrollSnapList()[slideIndex]; const opacity = clamp( 1 - wrappedDistance(slidePosition, currentPosition) * 8.4, @@ -47,10 +46,9 @@ const Carousel: React.FC = ({ slides, options }) => { useEffect(() => { if (!emblaApi) return; - + setOpacity(emblaApi); emblaApi.on("reInit", setOpacity).on("scroll", setOpacity); - }, [emblaApi]); return (