How can I detect if the user has clicked the previous/next arrow to toggle the value of the autoplay in react-multi-carousel?
return (
<Carousel
autoPlay={true}
autoPlaySpeed={4500}
customTransition="all .5"
transitionDuration={300}
infinite={true}
>
{movies.map((movie) => (
<img
key={movie.id}
style={{ width: "100%", height: "100%" }}
src={movie.image}
alt={movie.title}
/>
))}
</Carousel>
As Changoon Lee mentioned in their answer, you can use the
beforeChange
andafterChange
callbacks which are invoked each time before and after a sliding.If you only want to detect button clicks (and not keyboard slides or drags), you can create new button components and pass them as custom arrows. Your custom buttons will receive a list of props/state; one of them is the
react-multi-carousel
'sonClick
handler.You can pass your custom buttons to the Carousel as props (
customLeftArrow
andcustomRightArrow
).