leandrowd / react-responsive-carousel

React.js Responsive Carousel (with Swipe)
http://leandrowd.github.io/react-responsive-carousel/
MIT License
2.65k stars 626 forks source link

If InfiniteLoop is true, it comes out from the end of data #744

Open Leekee0905 opened 10 months ago

Leekee0905 commented 10 months ago

  const slides = Array.from({ length: 4}).map((_, index) => (
    <Box key={index} style={{
      display: 'flex',
      flexDirection: 'row',
      justifyContent: 'center',
      alignItems: 'center'
    }}>
      {bookData
        .slice(index * itemPerPage, (index + 1) * itemPerPage)
        .map((item:any, itemIndex:number) => {
          return(
          <Box key={itemIndex}>
            <Paper  style={{ margin: '0 15px', height: '300px', width: '200px', cursor: 'pointer', marginBottom: '12px'}}>
                <img src={item.thumbnailUrl} alt='book' style={{height: '300px', width: '200px'}} loading='lazy'/>
            </Paper>
            <Typography sx={{fontSize: '12px', maxWidth: '200px',overflow: 'hidden', textOverflow: 'ellipsis',margin: '0 auto' }}>
                {item.title}
            </Typography>
          </Box>

        )})}
    </Box>
  ));

<Carousel
          showArrows={true}
          emulateTouch={true}
          showStatus={false}
          showThumbs={false}
          infiniteLoop={true}
          autoPlay={true}
          selectedItem={0}
          renderArrowPrev={(onClickHandler, hasPrev, label) =>
            hasPrev && renderCustomArrow(onClickHandler, label, 'prev')
          }
          renderArrowNext={(onClickHandler, hasNext, label) =>
            hasNext && renderCustomArrow(onClickHandler, label, 'next')
          }
          className="custom-carousel-container"
        >
          {slides}
</Carousel>

Desktop (please complete the following information):

If InfiniteLoop is True when the browser is rendered, it comes out from the end of the data even though the selectedItem is 0, and if InfiniteLoop is False, it comes out from the beginning

When you see four items on a carousel page when the length of the data is 10 If there are 2 items on the last page, the last 2 items will be on the first carousel page when it is rendered for the first time, and if you go back to the beginning when you turn the carousel page, you will see 4 original data

hunxjunedo commented 4 months ago

I think that is intended and for a purpose.

elkingarcia11 commented 3 months ago

Have you managed to resolve this issue? I'm encountering the same problem. The final item appears on the initial slide, despite being assigned the last index.

ib45kc commented 1 week ago

you can fix add ref and action sliderRef.current?.moveTo(0);