Swiper (init with promise)

This commit is contained in:
ilya-bkv 2024-04-15 07:43:48 +03:00
parent 66ed666b90
commit 78cde31943

View File

@ -49,12 +49,17 @@ export const ImageSwiper = (props: Props) => {
) )
onMount(async () => { onMount(async () => {
console.log("!!! onMount:");
const { register } = await import('swiper/element/bundle') const { register } = await import('swiper/element/bundle')
register() register()
SwiperCore.use([Pagination, Navigation, Manipulation]) 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(() => { onMount(() => {
const updateDirection = () => { const updateDirection = () => {
const width = window.innerWidth const width = window.innerWidth