Reputation: 1392
I am trying to click images with using react-responsive-carousel. And on Click it should direct to the Link onClickItem
. I have tried it with <Link>
and <a>
. Doesnt work.
const onClickItem = () => console.log('Item');
<Carousel
showStatus={false}
showThumbs={false}
autoPlay={true}
infiniteLoop={true}
swipeable={false}
emulateTouch={true}
//@ts-ignore
animationHandler="fade"
transitionTime={5000}
onClickItem={onClickItem}
>
{banners.map((banner) => (
<div className="block" key={banner.id}>
<Link href={banner.href}>
<a>
<div>
<Image src={banner.image} width={768} height={400} alt={'Banner image'} />
</div>
</a>
</Link>
</div>
))}
</Carousel>
How to detect on Click with this component?
Upvotes: 0
Views: 1255
Reputation: 102
define func on click
const doClick = (bannerId) => {console.log(bannerId)}
add some func in your map
{banners.map((banner) => ( <div onClick={doClick(banner.id)} className="block" key={banner.id}> <Link href={banner.href}> <a> <div> <Image src={banner.image} width={768} height={400} alt={'Banner image'} /> </div> </a> </Link> </div> ))}
Upvotes: 0