0

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?

wick3d
  • 1,164
  • 14
  • 41

1 Answers1

0
  1. define func on click

    const doClick = (bannerId) => {console.log(bannerId)}

  2. 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> ))}

FAOZI
  • 67
  • 6