DEV Community

Discussion on: Building a Lightbox with Hotwire and Swiper.js

Collapse
 
ahmednadar profile image
Ahmed Nadar • Edited

Thanks Julian, awesome articles as usual.
I'm facing an error and can't neither following your example nor fix it.

I 'd appreciate your input here. Besides, do you have a repo example?
Thanks...

    activeKeyValueChanged() {
        const activeSlide = this.swiper ? .slides.findIndex((slide) => slide.dataset.key == this.activeKeyValue);
                                                                ^
        this.swiper ? .slideTo(activeSlide, 0);
                              ^
    }
Enter fullscreen mode Exit fullscreen mode

Error > Expression expected.ts(1109)

Collapse
 
ahmednadar profile image
Ahmed Nadar

I was able to solve it.

Since it is a Ternary Operator (?:), I need to add : and what comes after it, as such:

activeKeyValueChanged() {
    const activeSlide = this.swiper ? this.swiper.slides.findIndex((slide) => slide.dataset.key == this.activeKeyValue) : 0;

    this.swiper ? this.swiper.slideTo(activeSlide, 0) : 0;
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
julianrubisch profile image
julianrubisch

Ah though I see you’re using typescript. Maybe it doesn’t support the nullish coalescing operator?

Collapse
 
julianrubisch profile image
julianrubisch

Sorry I‘m late to answer… apparently I made a copy/paste error there 🤦‍♂️