Skip to content

[Help]: Loop working with 4+ images? #859

Closed Answered by p-mylecharane
p-mylecharane asked this question in Help
Discussion options

You must be logged in to vote

Ok so i did a bit of digging and ended up writing a solution if it helps anyone in the future here. It basically checks to see if there are enough images to loop, and if not, it will make duplicates and add them back into the mix. See below:

import React, { useEffect, useState } from 'react'
import {
  PrevButton,
  NextButton,
  usePrevNextButtons
} from '@/components/CarouselButtons'
import useEmblaCarousel from 'embla-carousel-react'

export function EmblaCarousel({ images }) {
  // State to hold the extended image list with duplicates
  const [extendedImages, setExtendedImages] = useState(images)

  const [emblaRef, emblaApi] = useEmblaCarousel({
    loop: true,
    align: 'start',
  …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by p-mylecharane
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
resolved This issue is resolved question Question about how to achieve something
1 participant