(ref: RefObject<HTMLVideoElement>)
| 1 | import { useEffect, useState, type RefObject } from 'react' |
| 2 | |
| 3 | export function useVideoDimensions(ref: RefObject<HTMLVideoElement>) { |
| 4 | const [videoHeight, setVideoHeight] = useState(ref.current?.videoHeight ?? 0) |
| 5 | const [videoWidth, setVideoWidth] = useState(ref.current?.videoHeight ?? 0) |
| 6 | |
| 7 | useEffect(() => { |
| 8 | const video = ref.current |
| 9 | if (!video) return |
| 10 | const handler = () => { |
| 11 | setVideoHeight(video.videoHeight) |
| 12 | setVideoWidth(video.videoWidth) |
| 13 | } |
| 14 | video.addEventListener('resize', handler) |
| 15 | return () => { |
| 16 | video.removeEventListener('resize', handler) |
| 17 | } |
| 18 | }, [ref]) |
| 19 | |
| 20 | return { videoHeight, videoWidth } |
| 21 | } |
no test coverage detected