K
K
kirill3215922020-09-07 18:47:20
css
kirill321592, 2020-09-07 18:47:20

How to update react swiper when orientation change?

When i change orientation on tablet the slider breaks (shows 1 broken slide). Expected behavior ( 2 slides 50% width in portrait orientation). I try to fix with ref.current.swiper.update(), but it don't work

const ref = useRef()
const handleResize = () => {
  ref?.current.swiper.update()
}

useEventListener('resize', handleResize)

<Swiper
  loop
  watchOverflow
  ref={ref}
  className="apartment-swiper"
  breakpoints={{
    768: {
      slidesPerView: 'auto',
    },
    1280: {
      slidesPerView: 1,
    },
  }}
>
  {photo?.map((item, index) => (
    <SwiperSlide className="swiper-slide" key={index}>
      <img className="swiper-slide" src={item.url} alt="slide" />
    </SwiperSlide>
  ))}
</Swiper>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Danny Arty, 2020-09-08
@DanArst

This bug is about 3 years old. Here is the solution
If you suddenly don’t figure out how to do it, then read the thread here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question