maxmarinich / react-alice-carousel

React responsive component for building content galleries, content rotators and any React carousels
MIT License
832 stars 91 forks source link

ActiveIndex not working #299

Closed WeiWang120 closed 9 months ago

WeiWang120 commented 9 months ago

Hi I am trying to write a carousel that auto plays and stop auto-play once the activeIndex is updated

const ProductCarousel = ({ images, index = -1 }: ProductCarouselProps) => {
  console.log(index)
  return (
    <div className="w-full">
      <AliceCarousel
        autoPlay={index < 0}
        infinite
        // autoPlayStrategy="none"
        autoPlayInterval={1000}
        animationDuration={1000}
        // animationType="fadeout"
        responsive={responsive}
        // autoHeight
        disableButtonsControls
        items={images}
        activeIndex={index}
        // onSlideChanged={(item) => setActiveIndex(item.item)}
      />
    </div>
  )
}

But when the index is updated, the carousel does not jump to the correct one, it simply does nothing

WeiWang120 commented 9 months ago

I think it is because the images changed, so the whole component rerendered