Created
March 19, 2024 08:15
-
-
Save mike-at-redspace/2aeda541caed88c425b002067b72aa39 to your computer and use it in GitHub Desktop.
Client Loaded Swiper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
import { Swiper, SwiperSlide } from "swiper/react" | |
import useSWR from "swr" | |
const fetcher = (url) => | |
fetch(url, { | |
headers: { | |
Authorization: `Bearer YOUR_JWT_TOKEN` | |
} | |
}).then((res) => res.json()) | |
function LazyLoadedSwiperCarousel() { | |
const { data, error } = useSWR( | |
"https://qa-neutron-api.paramount.tech/api/3.4/screen/...", | |
fetcher | |
) | |
if (error) return <div>Failed to load</div> | |
if (!data) return <div>Loading...</div> | |
return ( | |
<Swiper | |
spaceBetween={50} | |
slidesPerView={1} | |
navigation | |
pagination={{ clickable: true }} | |
scrollbar={{ draggable: true }} | |
onSwiper={(swiper) => console.log(swiper)} | |
onSlideChange={() => console.log("slide change")} | |
> | |
{data.map((item, index) => ( | |
<SwiperSlide key={index}> | |
<img src={item.imageUrl} alt={item.description} loading="lazy" /> | |
</SwiperSlide> | |
))} | |
</Swiper> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment