YIZHUANG / react-multi-carousel

A lightweight production-ready Carousel that rocks supports multiple items and server-side rendering with no dependency. Bundle size 2kb.
MIT License
1.28k stars 288 forks source link

Custom click to fetch data #238

Closed bipinstha7 closed 3 years ago

bipinstha7 commented 3 years ago

Hi, can we have a custom click function that fetches data and scrolls too? I have gone through the code, there is a default next and previous function. How do we fetch and scroll?

I tried with

const customClick = () => {
fetchData()
 infinite = true // initially infinite is false
}

const CustomRightArrow = ({ onClick, ...rest }) => {
  const handleClick = () => {
    rest.customClick();
    onClick();
  };

  return (
      <button
        aria-label="Go to next slide"
        className="react-multiple-carousel__arrow react-multiple-carousel__arrow--right"
        onClick={handleClick}
        type="button"
      />
  );
};

but the infinite scroll doesn't work. Scrolling stops as soon as it reaches to last element. The arrow icon is there but no scrolling. Could you please help me?

NOTE: When I change window width (zoom in or zoom out) infinite scrolling works fine.

bipinstha7 commented 3 years ago

I managed to make it work for me. If anyone ever has this problem, here is the solution. This package uses the window's "resize" event to adjust the width and the content. So whenever the data has changed bubble up the resize event which solves the problem.