React-slick: double items showed

Created on 5 Apr 2018  路  19Comments  路  Source: akiran/react-slick

SliderProps: {
slidesToShow: 2,
infinite: true,
}

With these props if you pass to the slider only 1 item, it will show cloned one under the first slide.

screenshot 21

bug queued

Most helpful comment

I faced with same bug, my temporary fix:

infinite: items.length > 3

All 19 comments

Hi, when can I wait for the react-slick npm update according to these issue?)

Is there any workaround until you update this?

I faced with same bug, my temporary fix:

infinite: items.length > 3

I'm having the same issue, @SnowDiamond's solution helped, but to give more info about this issue, I belive it happens if item number is smaller then slidesToShow
In my opinion there should be a trigger that sets infinite to false if item number is smaller than slidesToShow

You can create a state for infinite, and check if your array is big enough to put infinite on true:

infinite: this.state.infinite,

if (yourarray.length <= 2) {
    this.setState({infinite: false})
} else {
    this.setState({infinite: true})
}

I am experiencing this problem but finding that it occurs unless the slides to show number is smaller than the item length

I am experiencing this problem but finding that it occurs unless the slides to show number is smaller than the item length

The solution provided by SnowDiamond should work.

infinite false can do the job

@narendersaini32

infinite false can do the job

A potential quick-fix, but not a solution for the problem.

I have something like this for the workaround:

import Slider from "react-slick";

import Slider from "react-slick";

export default function Carousel({ children }) {
  const settings = {
        dots: true,
    infinite: children.length > 4,
    slidesToShow: 4,
  };

  return <Slider {...settings}>{children}</Slider>;
}

It's 2020 already, just fix it.

I got the same problem . :(.

Got this error and it took me precious nights to see this quick workaround provided by SnowDiamond. @React-Slick

If you are using typescript and defining the type of children as ReactNode you will get an error when using length.

I solved this by using the following:

const MAX_SLIDES = 7; 
const infinite = children ? React.Children.count(children) > MAX_SLIDES : false;
  const settings = {
    dots: true,
    arrows: true,
    infinite,
    speed: 500,
    slidesToShow: MAX_SLIDES,
    slidesToScroll: MAX_SLIDES,
  };

return(<Slider {...settings}>{children}</Slider>)

But agree surely a fix can be put in for this?

This problem is there for me even with infinite: false. (I'm using Ant's Carousel component which uses React Slick)
This is the third unresolved issue I have run into in a single night for the simplest use case using this library :(

There's also another problem - What happens if there's a different value for slidesToShow for each device breakpoint?

We would have to verify the current breakpoint and then access the responsive array settings to grab the slidesToShow value.

There's also another problem - What happens if there's a different value for slidesToShow for each device breakpoint?

We would have to verify the current breakpoint and then access the responsive array settings to grab the slidesToShow value.

@LauraBeatris did you happen to find a workaround for this specific problem?

Information about slidesToShow in current responsive is stored deep down in slick guts.
slickRef.current.innerSlider.track.props.slidesToShow

infinite: items.length > 3
it's the great way
thanks SnowDiamond

Was this page helpful?
0 / 5 - 0 ratings

Related issues

briziel picture briziel  路  3Comments

will88 picture will88  路  3Comments

PolGuixe picture PolGuixe  路  3Comments

walker-jiang picture walker-jiang  路  3Comments

quarklemotion picture quarklemotion  路  4Comments