question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mapped Data in Swiper not rendering correctly.

See original GitHub issue

react-id-swiper: ^3.0.0 swiper: ^5.3.6

When mapping data to the swiper component, as I have done in previous versions, the swiper renders all items ignoring the slidesPerView, centeredSlides parameters set. Here are my params:

const params = {
    containerClass: 'testimony-carousel',
    loop: true,
    lazy: true,
    rebuildOnUpdate: true,
    pagination: {
      el: '.swiper-pagination',
      dynamicBullets: true,
      clickable: true
    },
    centeredSlides: true,
    slidesPerView: 1
  }

inside the component it is set like this:

<Swiper {...params}>
      {
        data.testimonies.map((data, i) => (
          <Testimony key={i} data={data} />
        ))
      }
 </Swiper>

The styling has been imported as well, still just rendering all slides inside the swiper container

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
elias-garciacommented, Apr 12, 2020

I had the same problem @trevans24. Having a look at the Swiper Docs, I’ve figured out that they are wrapping each slide in a div with a class named swiper-slide. So this code works as expected:

<Swiper {...params}>
  {edges.map(({ node: review }, index) => (
    <div className="swiper-slide" key={index}>
      <Review
        authorName={review.author.name}
        authorImage={review.author.image}
        rating={review.rating}
        comments={review.comments}
      />
    </div>
  ))}
</Swiper>
0reactions
Amealkycommented, Dec 26, 2022

Same problem here

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swiper js for React does not render children properly
I have problem with rendering children into Swiper component. I use swiper in two places (Blog and Portfolio sections) so I created CardsSlider ......
Read more >
Swiper React Components
SwiperSlide component can accept render function that receives an object with the following properties: isActive - true when current slide is active; isPrev...
Read more >
Swiper slider doesn't rendered and works properly - Questions
I want to add Swiper slider to my react app with F7. But there many issues: The pagination dots are partially rendered -...
Read more >
how to get current slide element index in swiper js react
Pagination correctly shows dots for the added slides, so Swiper sees them, but it never changes slide. If first render results in more...
Read more >
Encountered Two Children with the Same Key — React Fix
The Problem When you are rendering React components in a map ... and may or may not correctly update your component when it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found