Swiper js and React: How to pass React state when swiping left or right to prev/next slide #5617
Unanswered
meesfrenkelfrank
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Check that this is really a bug
Reproduction link
https://codesandbox.io/s/swiper-react-state-swiper-8-op0ij8
Bug description
I am using Swiper js for my React slider.
I'am looping over an Object
Object.values(FilterMap).map((Filter, index)
and return the Swiper slides.I have some (filter) buttons as swiper slides, to filter content when selecting/clicking a slide button.
The active slide (which gets css class
swiper-slide-active
by the swiper api) should always be centered. That's working fine from the api with the following props:centeredSlides
andslideToClickedSlide
But when I 'swipe' the slides to left or right, the swiper active slide get centered, but my other logic on the selected button
data-active={true}
is now not in sync with swipers active slide.How to fix this?
Here is the CodeSandbox, with an example what I have so far.
Expected Behavior
When swipe the slide to prev or next slide, the passed state from the
onChange
propdata-active={true}
will be applied when swiping the slides. Sodata-active={true}
and slide with css classswiper-slide-active
are always centered.No response
Actual Behavior
No response
Swiper version
8.0.7
Platform/Target and Browser Versions
Google Chrome Version 99.0.4844.84
Validations
Would you like to open a PR for this bug?
Beta Was this translation helpful? Give feedback.
All reactions