Emiliano-Bucci / react-spring-carousel-js

A new Carousel experience for the modern Web
https://react-spring-carousel-js.emilianobucci.com
80 stars 6 forks source link

How to get it autoplay #1

Closed muhaimincs closed 3 years ago

Emiliano-Bucci commented 3 years ago

@muhaimincs Hi! Sorry for the delay :) The autoplay functionality isn't built inside the Carousel, as every developer may have particular/different needs, and i wanted to maximum the extensibility of the library. In order to implement the autoplay functionality you can do the following:

useEffect(() => {
    const interval = setInterval(() => {
      slideToNextItem();
    }, 3000);

    return () => {
      window.clearInterval(interval);
    };
  }, [slideToNextItem]);

return (
   <div>{carouselFragment}</div>
) 

Let me know if you need anything else! :)

muhaimincs commented 3 years ago

understood. Thanks!