1- import { Fragment , useMemo , useRef } from 'react'
1+ import { useEffect , useMemo , useRef } from 'react'
22import type { MediaItem } from './types'
33import { useMediaItemPlaybackTracker } from './utils/useMediaItemPlaybackTracker'
4- import { useEffect } from 'react'
54
65type Props = {
7- item : MediaItem
6+ item : MediaItem
87}
98
109export const MediaItemRenderer = ( { item } : Props ) => {
@@ -23,46 +22,31 @@ export const MediaItemRenderer = ({ item }: Props) => {
2322 } else {
2423 video . play ( ) . catch ( ( ) => { } )
2524 }
26- } , [ item ] )
25+ } , [ item . type , item . hidden ] )
2726
28- const commonStyle = useMemo ( ( ) => ( {
27+ const mediaStyle = useMemo ( ( ) => ( {
2928 position : 'absolute' as const ,
3029 top : 0 ,
3130 left : 0 ,
3231 width : '100%' ,
3332 height : '100%' ,
3433 objectFit : 'cover' as const ,
3534 zIndex : item . hidden ? 0 : 1 ,
36- opacity : item . hidden ? 1 : 0.5 ,
3735 } ) , [ item . hidden ] )
3836
39- const imageStyle = useMemo ( ( ) => ( {
40- ...commonStyle
41- } ) , [ commonStyle ] )
42-
43- const videoStyle = useMemo ( ( ) => ( {
44- ...commonStyle
45- } ) , [ commonStyle ] )
46-
4737 if ( ! item . preload && item . hidden ) return null
4838
49- return (
50- < Fragment key = { item . id } >
51- { item . type === 'image' ? (
52- < img
53- src = { item . src }
54- style = { imageStyle }
55- />
56- ) : (
57- < video
58- ref = { videoRef }
59- style = { videoStyle }
60- loop
61- muted
62- >
63- < source src = { item . src } type = "video/mp4" />
64- </ video >
65- ) }
66- </ Fragment >
39+ return item . type === 'image' ? (
40+ < img key = { item . id } src = { item . src } style = { mediaStyle } />
41+ ) : (
42+ < video
43+ key = { item . id }
44+ ref = { videoRef }
45+ style = { mediaStyle }
46+ loop
47+ muted
48+ >
49+ < source src = { item . src } type = "video/mp4" />
50+ </ video >
6751 )
68- }
52+ }
0 commit comments