This is a:
let mySwiper;
useEffect(() => {
mySwiper = new Swiper('.swiper-container', {
// slidesPerView: 2.1,
loop: true,
slidesPerView: '2',
centeredSlides: true,
pagination: {
el: '.swiper-pagination',
clickable: true,
},
});
})`
Should be initialized Correctly.
Giving warning and not initializing correctly.
Assignments to the 'mySwiper' variable from inside React Hook useEffect will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside useEffect.
const swiperReference = useRef(null);
useLayoutEffect(() => {
swiperReference.current = new Swiper(swiperContainerRef.current, {
// parameters
});
}, []);
console.log(swiperReference.current); // access to the swiper instance
Closing as not related to Swiper itself
Most helpful comment