"use client"; import Image from "next/image"; import chicagoPic from "@/public/content/homepage-carousel/chicago.jpg"; import indianapolisPic from "@/public/content/homepage-carousel/indianapolis.webp"; import naturePic from "@/public/content/homepage-carousel/nature.jpg"; import { useEffect, useState } from "react"; import { useTransition, animated } from "@react-spring/web"; interface Props { className?: string; } const Carousel = ({ className }: Props) => { const [backgroundIndex, setBackgroundIndex] = useState(0); const backgroundImages = [ { image: chicagoPic, desc: "Chicago Skyline" }, { image: indianapolisPic, desc: "Indianapolis Skyline" }, { image: naturePic, desc: "Two women hiking in the mountains" }, ]; useEffect(() => { const interval = setInterval(() => { setBackgroundIndex( (prevIndex) => (prevIndex + 1) % backgroundImages.length ); }, 9000); return () => clearInterval(interval); }, []); const transitions = useTransition(backgroundIndex, { key: backgroundIndex, from: { opacity: 0 }, enter: { opacity: 1 }, leave: { opacity: 0 }, config: { duration: 2500 }, exitBeforeEnter: true, }); return transitions((style, item) => ( {backgroundImages[item].desc} )); }; export default Carousel;