React-slick: Changing slide works incorrect when infinite is false and initialSlide > 1

Created on 10 Dec 2020  路  4Comments  路  Source: akiran/react-slick

Changing slide when initialSlide > 1 and infinite is false works wrong.
When I swipe right I expect to see next slide(initial + 1), but I always see second slide as next, when I swipe left, I always get first slide.
Also same behaviour when I click on arrows on this example, but with initialSlide: 2, infinite: false.
I think that same behaviour we have always when initial slide is set and infinite setting is false.

Link to stackblitz to reproduce. https://stackblitz.com/edit/react-brc9ys?file=src%2FApp.js
Versions:

  • react-slick: 0.27.13
  • react: 17.0.1

Is any recipes how to solve it?
Similar issue: https://github.com/akiran/react-slick/issues/1874

bug High

Most helpful comment

Created bug fix pull request. https://github.com/akiran/react-slick/pull/1950

All 4 comments

Created bug fix pull request. https://github.com/akiran/react-slick/pull/1950

@akiran #1950 ready to merge

Anyone who can't wait this issue fixed, you can use this as workaround

  const [hasSetPosition, setHasSetPosition] = useState(false);

  useEffect(() => {
    if (slider.current && !hasSetPosition) {
      slider.current?.slickGoTo(initialSlidePosition);
      setHasSetPosition(true);
    }
  }, [initialSlidePosition, hasSetPosition, slider]);

Swipe or slick's methods for navigate will work correctly.

Any update about this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eternalsky picture eternalsky  路  3Comments

jfamousket picture jfamousket  路  3Comments

PolGuixe picture PolGuixe  路  3Comments

walker-jiang picture walker-jiang  路  3Comments

vugman picture vugman  路  3Comments