Как типизировать Swiper React?

Всем привет, возникла вот такая проблема, я ref добавил к swiper, но обращаться к newsListSwiperRef.current?.swiper можно только в том случае, если передать в типы any, а я хочу строгую типизацию сделать, но я не могу понять, какой тип нужно передать ,что бы это сработало, что я делаю не так, как сделать типизацию?

import React, {FC, useRef} from 'react';
import {Swiper, SwiperSlide} from "swiper/react";

const NewsListSlider:FC = () => {

    const newsListSwiperRef = useRef<any>(null)

    const nextElementSwiper = () => {
        if(!newsListSwiperRef.current)
            return false

        newsListSwiperRef.current?.swiper?.slideNext()

    }

    return (
        <div className={`w-1/2`}>
            <Swiper
                ref={newsListSwiperRef}
                slidesPerView={2}
            >

                <SwiperSlide>
                    <div className={`bg-black text-yellow`}>
                        test2
                    </div>
                </SwiperSlide>

                <SwiperSlide>
                    <div className={`bg-black text-yellow`}>
                        test2
                    </div>
                </SwiperSlide>

                <SwiperSlide>
                    <div className={`bg-black text-yellow`}>
                        test2
                    </div>
                </SwiperSlide>

                <SwiperSlide>
                    <div className={`bg-black text-yellow`}>
                        test2
                    </div>
                </SwiperSlide>

            </Swiper>

            <div onClick={nextElementSwiper}>
                test
            </div>
        </div>
    );
};

export default NewsListSlider;
  • Вопрос задан
  • 1631 просмотр
Решения вопроса 1
Alexandroppolus
@Alexandroppolus
кодир
import {Swiper, SwiperSlide, SwiperRef} from "swiper/react";

...
const newsListSwiperRef = useRef<SwiperRef>(null);
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы