Utilize the onSwiper property to access your swiper instance and store it using the useState hook. This will allow you to interact with the swiper API in any way you desire. Enjoy exploring new coding possibilities.
export default function App() {
const [swiperRef, setSwiperRef] = useState(null);
const prevHandler = () => {
swiperRef.slidePrev();
};
const nextHandler = () => {
swiperRef.slideNext();
};
return (
<>
<button onClick={prevHandler}>Previous</button>
<button onClick={nextHandler}>Next</button>
<Swiper spaceBetween={50} onSwiper={(swiper) => setSwiperRef(swiper)}>
<SwiperSlide>Slide 1</SwiperSlide>
<SwiperSlide>Slide 2</SwiperSlide>
<SwiperSlide>Slide 3</SwiperSlide>
<SwiperSlide>Slide 4</SwiperSlide>
</Swiper>
</>
);
}