React JS Swiper loop cannot correctly traverse objects
P粉835428659
2023-08-15 22:44:32
<p>My Swiper isn't working in React, I've tried fixing it multiple times without success. Swiper is already the latest version. </p>
<pre class="brush:php;toolbar:false;">import React from "react";
import "./testimonial.css";
import { Data } from "./Data";
import {Swiper, SwiperSlide} from "swiper/react";
import "swiper/css";
import "swiper/css/pagination";
import {Pagination} from "swiper/modules"
const Testimonials = () => {
return (
<section className="testimonial container section">
<h2 className="section_title">My client said</h2>
<span className="section_subtitle">Recommendation Letter</span>
<Swiper className="testimonial_container"
loop={true}
grabCursor={true}
spaceBetween={24}
pagination={{
clickable: true,
}}
breakpoints={{
576: {
slidesPerView: 2,
},
768: {
slidesPerView: 2,
spaceBetween: 48,
},
}}
modules={[Pagination]}>
{Data.map(({id,image,title,description})=>{
return(
<SwiperSlide className="testimonial_card" key={id}>
<img src={image} alt="" className="testiomonial_img"/>
<h3 className="testimonial_name">{title}</h3>
<p className="testimonial_description">{description}</p>
</SwiperSlide>
)
})}
</Swiper>
</section>
);
};
export default Testimonials;</pre>
<p>I tried different syntax forms with no success. I want to be able to infinitely scroll through my objects, but it always gets stuck on the second slide. </p>
I found some potential problems with your code: