swiper: Children does not render properly (after wrapper component)
Hello, I have already posted on stackoverflow about rendering children in swiperjs using React.
https://stackoverflow.com/questions/66993033/swiper-js-for-react-does-not-render-children-properly I use:
"gatsby": "^3.0.1",
"react": "^17.0.1",
"swiper": "^6.5.0",
What You Did
I want to render children like this:
<Swiper>{children}<Swiper/>
But children are rendered after swiper wrapper.
Expected Behavior
I want to pass all children and render them inside Swiper wrapper because I fetch data from external source (headless cms)
Actual Behavior
Swiper Slides are rendered after Swiper component what makes cards invisible in page content.
The code you can see in stack overflow and this commit of my project https://github.com/tobiaszciesielski/tciesielski.pl/pull/1/commits/5500865d7eef1a99facb03e3dedd987ee1ce6033
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 17
- Comments: 15
Had the same issue, and fixed it with an even simpler solution. Let me know if you see any concerns.
All I needed to do was change the displayName of my ‘custom slide’ component to match the “SwiperSlide” component so the parent “Swiper” thinks the direct child is “SwiperSlide”.
This makes me really sad.
@jomarquez21 I encoutered same issue when i tried to use subcomponents and here is the workaroud i found :
Thanks for the solution @msoyka.
Sharing a ‘deeper slides’ situation here. Just the first level needs the edit.
@nolimits4web is this considered an error? If this is a bug, can you add the corresponding tag?
In case it helps anyone, I just recently faced this issue as well but in this context:
I was pulling from different components that each were wrapped in a SwiperSlide (inside the component). Reading up on the above shows that Swiper wants the SwiperSlides to be a direct child so to get it working I removed the SwiperSlide inside each component and wrapped them with SwiperSlide outside of the component, inside the Carousel component.
From
Carousel.tsx
Slide.tsx
To
Carousel.tsx
Slide.tsx