Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

<SwiperSlide> is not getting created inside a map function

I am trying to dynamically create a SwiperSlide tag inside a map function. The docs in Swiper JS are hard coded but I would like them to be dynamically.

The replicable code is here – https://codesandbox.io/p/sandbox/swiper-react-effect-coverflow-forked-67pckv?file=%2Fsrc%2FApp.jsx%3A21%2C30

in Line 35 even if I try to specify the SwipeSlide inside the map using JSX syntax it’s not reflecting anything in the output. Need help in this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{items.map((item) => {
    <SwiperSlide>{item}</SwiperSlide>
})}

>Solution :

You are not returning the SwiperSlide from map function, please update as following:

{items.map((item) => {
   return(
     <SwiperSlide>{item}</SwiperSlide>
   )
})}

Or you can do this as well:

{items.map((item) => (
     <SwiperSlide>{item}</SwiperSlide>
))}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading