Skip to content

Changing slideInterval prop dinamically #577

@jpaladin

Description

@jpaladin

My use case needs an ability to set duration of the slide different for each i.e.

const images = [
    {
      original: "https://picsum.photos/id/1018/1000/600/",
      thumbnail: "https://picsum.photos/id/1018/250/150/",
      duration: 1000
    },
    {
      original: "https://picsum.photos/id/1015/1000/600/",
      thumbnail: "https://picsum.photos/id/1015/250/150/",
      duration: 5000
    }
]

So I tried setting the slideInterval prop dynamically in the onBeforeSlide prop callback like this using the slideInterval state variable

<ImageGallery
        items={images}
        slideInterval={slideInterval}
        autoPlay={true}
        onBeforeSlide={(nextIndex) => setSlideInterval(images[nextIndex].duration)}
 />

This does not apply the newly set slideInterval

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions