Remove a slide in Swiper React

Viewed 76

I want to remove the first slide in react with swiper js. I looked in the API and found swiper.removeSlide(slideIndex), but that doesn't seem to work. I am using the useSwiper hook. But still, I am getting 'swiper.removeSlide is not a function'. Anyone how I could handle this?

import React, { useEffect } from "react";
import { useSwiper } from "swiper/react";

const DeleteSlide = ({}) => {
  const swiper = useSwiper();

  useEffect(() => {
    setTimeout(() => {
      swiper.removeSlide(0);

      swiper.activeIndex = 0;
      swiper.initialSlide = 0;
    }, 9000);
  }, []);

  return <></>;
};

export default DeleteSlide;
1 Answers

I think if you are passing the array of images for swiper then while passing the array, you can use array.slice(1, images.length-1) so the first image will be excluded

Related