E-commerce using Next.JS

Solution retrospective
I am having a layout shift sometimes when loading the images. Could this be related to Images component? Thanks in advance.
Please log in to post a comment
Log in with GitHubCommunity feedback
- @cancomertpay
Hi Josh,
You can try more basic carousel logic like this:
... const [currentImgIndex, setCurrentImgIndex] = useState(0); const nextImage = () => { if (currentImgIndex < images.length - 1) { setCurrentImgIndex((prev) => prev + 1); } else { setCurrentImgIndex(0); } }; const prevImage = () => { setCurrentImgIndex((prev) => prev - 1); if (currentImgIndex === 0) { setCurrentImgIndex(images.length - 1); } }; const handleThumbnailClick = (index) => { setCurrentImgIndex(index); }; ... return images.map((item,index) => ( <div style={{ opacity: index === currentImgIndex ? 1 : 0, transition: "opacity 1s ease", width: index === currentImgIndex ? "100%" : "auto", }} > <img src={item} alt={"..."} /> </div> ))
This was just an example to explain the logic, I hope it helped. :)
Marked as helpful
Join our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord