-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCardVideo.tsx
More file actions
32 lines (27 loc) · 925 Bytes
/
CardVideo.tsx
File metadata and controls
32 lines (27 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { useState, useEffect } from 'react'
import ReactPlayer from 'react-player'
export interface CardVideoProps {
source: string
}
export const CardVideo = ({ source }: CardVideoProps) => {
const [initialRender, setInitialRender] = useState(false)
// Run after first render and load the video player
useEffect(() => {
setInitialRender(true)
}, [])
// Prevent the component from rendering and avoid hydration error
if (!initialRender) {
return (
<div className="relative pt-[56.25%] bg-cu-black-800 mb-2 rounded-t-lg overflow-hidden">
<p className="hidden">Loading video</p>
</div>
)
} else {
return (
<div className="relative pt-[56.25%] bg-cu-black-800 mb-2 rounded-t-lg overflow-hidden">
<ReactPlayer src={source} className="absolute top-0 left-0" width="100%" height="100%" controls />
</div>
)
}
}
CardVideo.displayName = 'Card.Video'