Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48984

Changing slides using buttons above swiper

$
0
0

Hi there, I’m new to Ionic React.

I’m trying to change slides using buttons that are placed above Swiper onClick:

const Tab: React.FC = () => {
  const swiper = useSwiper();

  return (
    <IonPage>
        <IonItem class="labels">
          <IonButton onClick={() => swiper.slideNext() }>
            <IonIcon  icon={chatbubbles} color="primary" />
            <IonLabel> Chat</IonLabel>
          </IonButton>
        </IonItem>
        <Swiper className="mySwiper"
          onSwiper={(swiper) => console.log(swiper)}
          onSlideChange={() => console.log('slide change')}
        >
          <SwiperSlide>Chat</SwiperSlide>
          <SwiperSlide>Stories</SwiperSlide>
          <SwiperSlide>Topics</SwiperSlide>
          <SwiperSlide>Private</SwiperSlide>
        </Swiper>
    </IonPage>
  );
};

Since Swiper is not initialized before the button, how do I pass swiper to onClick? E.g.

Uncaught TypeError: Cannot read properties of null (reading 'slideNext')

Thanks!

9 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 48984

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>