Ok so, how do I build a slideshow? Well, of course, that's a pretty easy thing to do with React Spring Carousel 🤟
import { useTransitionCarousel } from 'react-spring-carousel'
export function Component() {
const {
carouselFragment,
slideToPrevItem,
slideToNextItem
} = useTransitionCarousel({
items: (
<CarouselItem color={i.color}>
{i.title}
</CarouselItem>
),
});
useEffect(() => {
const timer = setInterval(() => {
slideToNextItem();
}, 1500);
return () => {
window.clearInterval(timer);
};
// You MUST add the slide methods to the dependency list useEffect!
}, [slideToNextItem]);
return (
<div>
<button onClick={slideToPrevItem}>Prev item</button>
{carouselFragment}
<button onClick={slideToNextItem}>Next item</button>
</div>
);
}