akiran / akiran/react-slick

slickGoTo inside useEffect doesn't work.

Đang mở
#2,037 20 bình luận 3 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
11.9k
Fork
2.1k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

so I have following problem, I want my slider to go back to slide 6 after if anyone would try to swipe further.
However it doesn't work. UseEffect is being triggered, IF condition is being met, but the function won't run.
If I put the same function call inside JSX like first snippet below it works how it should:
```
sliderRef.current.slickGoTo(5)} >go to slide 6
```

This is my code:
```
const [activeSlide, setActiveSlide] = useState(0)
const sliderRef = useRef(null)
const settings = {
variableWidth: true,
speed: 500,
pauseOnHover: false,
swipeToSlide: false,
focusOnSelect: false,
infinite: false,
slidesToScroll: 1,
arrows: false,
beforeChange: (current, next) => setActiveSlide(next)
}
```

```
useEffect(() => {
if (window.innerWidth > 1100 && activeSlide > 5) {
sliderRef.current.slickGoTo(5)
}
}, [activeSlide])
```

```

```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.