Mike
Mike

Reputation: 83

Remove a slide in Swiper React

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;

Upvotes: 1

Views: 2194

Answers (2)

solution Manager
solution Manager

Reputation: 46

You need to import 'Manipulation' module.

import SwiperCore, { Manipulation } from 'swiper';

SwiperCore.use([ Manipulation ]);

This works for me.

Upvotes: 3

Milan Poudel
Milan Poudel

Reputation: 792

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

Upvotes: 1

Related Questions