From 78cde31943c801e2971e2a3b0bc65f93aa5be8ec Mon Sep 17 00:00:00 2001 From: ilya-bkv Date: Mon, 15 Apr 2024 07:43:48 +0300 Subject: [PATCH] Swiper (init with promise) --- src/components/_shared/SolidSwiper/ImageSwiper.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/_shared/SolidSwiper/ImageSwiper.tsx b/src/components/_shared/SolidSwiper/ImageSwiper.tsx index 1de1fe65..d018632c 100644 --- a/src/components/_shared/SolidSwiper/ImageSwiper.tsx +++ b/src/components/_shared/SolidSwiper/ImageSwiper.tsx @@ -49,12 +49,17 @@ export const ImageSwiper = (props: Props) => { ) onMount(async () => { + console.log("!!! onMount:"); const { register } = await import('swiper/element/bundle') register() SwiperCore.use([Pagination, Navigation, Manipulation]) - mainSwipeRef.current?.swiper?.on('slideChange', handleSlideChange) + while (!mainSwipeRef.current || !mainSwipeRef.current.swiper) { + await new Promise(resolve => setTimeout(resolve, 10)); // wait 10 ms + } + mainSwipeRef.current.swiper.on('slideChange', handleSlideChange); }) + onMount(() => { const updateDirection = () => { const width = window.innerWidth