diff --git a/packages/gallery/src/components/item/media/GalleryUI.tsx b/packages/gallery/src/components/item/media/GalleryUI.tsx index b108fae5a..89e380eca 100644 --- a/packages/gallery/src/components/item/media/GalleryUI.tsx +++ b/packages/gallery/src/components/item/media/GalleryUI.tsx @@ -1,25 +1,45 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { useGalleryUI } from '../../../context/GalleryContext'; + +type ComponentType = React.ComponentType<{ size: number }>; + +interface GalleryComponents { + videoPlayButton: ComponentType; + rotateArrow: ComponentType; +} + const galleryUiComponents = { videoPlayButton: React.lazy(() => import(/* webpackChunkName: "defaultPlayButton" */ './playButton')), rotateArrow: React.lazy(() => import(/* webpackChunkName: "defaultRotateArrow" */ './rotateArrow')), }; + interface GalleryUIProps { size: number; - type: 'videoPlayButton' | 'rotateArrow'; + type: keyof GalleryComponents; } export const GalleryUI = ({ type, size }: GalleryUIProps): JSX.Element => { - let Component; - + const [isMounted, setIsMounted] = useState(false); const galleryUI = useGalleryUI(); + + useEffect(() => { + setIsMounted(true); + }, []); + + if (!isMounted) { + return <>; + } + if (typeof galleryUI?.[type] === 'function') { return galleryUI[type](size); - } else if (galleryUiComponents[type]) { - Component = galleryUiComponents[type]; - } else { + } + + const Component = galleryUiComponents[type]; + + if (!Component) { return <>; } + return ( }>