kidjp85 / react-id-swiper

A library to use idangerous Swiper as a ReactJs component which allows Swiper's modules custom build
https://react-id-swiper.ashernguyen.site/
MIT License
1.49k stars 154 forks source link

In 4.0.0, getSwiper is removed, what is the replacement? #444

Closed 615349 closed 4 years ago

615349 commented 4 years ago

I have below snippet

const [swiper, updateSwiper] = useState(null);

  useEffect(() => {
    if (swiper !== null) {
      const onSlideChangeHandler = () => onSlideChange(swiper.realIndex);

      swiper.on('slideChange', onSlideChangeHandler);

      return () => {
        swiper.off('slideChange', onSlideChangeHandler);
      };
    }
  }, [onSlideChange, swiper]);

  const params = {
    initialSlide: currentIndex,
    getSwiper: s => updateSwiper(s),
    shouldSwiperUpdate: true
  };

so I have one params to get the swiper instance, and have callback on swiper slide change, but in the latest 4.0.0, getSwiper is removed.

what is the replacement? why cannot it be backward compatible?

kidjp85 commented 4 years ago

Let use ref instead. You can find more info from README