Lets say I have 3 slides
I really need this activeSlideKey, for some reason I can't even get it work. But I see that you have said about this issues. Was there any progress since then?
@IlimaVIP do you pass activeSlideKey as a number of slide?
If you create slider like this:
<Swiper {...swiperSettings}>
{slides.map((slide, index) => (<div key={index}>[some markup]</div>))}
</Swiper>
then you should pass activeSlideKey as a string, e.g. if you want to activate a second slide, you should write: activeSlideKey: "1" (not activeSlideKey: 1 ), though the key type passed in map is integer.
Hi @kolyabokov , sorry for late response. Can you provide live demo from prepared Codesandbox ? You can find it from README . Thanks!
Yes @kolyabokov , I have tried this as well:
<Swiper {...params} activeSlideKey='5'>
...
</Swiper>
If there's a way to solve this problem, it would be great.
The conversations on this are still going on:
@IlimaVIP , which value are you using for activeSlideKey ? It's not index slide number, it should be the key value you provide when render slide list.
const renderItem => (item, idx) => <div key={`${item.name}_${idx}`}>{item.name}</div>
return <Swiper>{items.map(renderItem)}</Swiper>
From the example above, key here should be slide_2_1 when second item's name is slide_2. If you want the initial slide display second item, you should provide key="slide_2_1"
Thank you @kidjp85 and @kolyabokov It worked :+1: :100:
@kidjp85 Why swiper slides to activeSlideKey in componentDidUpdate lifecycle method, not in componentDidMount only? componentDidUpdate will be called even when nothing actually changes for swiper component itself, for example when parent component is rerendered.
Here is the sandbox example: https://codesandbox.io/s/nice-moser-stv5o?fontsize=14&hidenavigation=1&theme=dark
Third slide is activated by default. If I slide to the first slide, and then click "Increase" button (which just changes the component state, but doesn't change any swiper props), swiper will slide back to third slide. I think this is confusing and wrong bahaviour.
@kolyabokov , we no longer use React Class anymore so every logic stay in useEffect
Most helpful comment
@IlimaVIP do you pass activeSlideKey as a number of slide?
If you create slider like this:
then you should pass activeSlideKey as a string, e.g. if you want to activate a second slide, you should write:
activeSlideKey: "1"(notactiveSlideKey: 1), though the key type passed inmapis integer.