Video.js 1017 Bytes
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { useEffect, useState } from 'react'
import movieApi from '../apis/movie.api.js'
const Video = (props) => {
    const [videoUrls, setVideoUrls] = useState([])
    useEffect(() => {
        getVideos()
    }, [])

    async function getVideos() {
        try {
            const data = await movieApi.getVideosfromTM(props.movieId)
            setVideoUrls(data)
        } catch (error) {
            console.log(error)
        }
    }
    return (
        <div>
            {videoUrls.length > 0
                ? videoUrls.map(el => (
Jiwon Yoon's avatar
Jiwon Yoon committed
21
                    <div className="mt-5 pb-5">
Jiwon Yoon's avatar
Jiwon Yoon committed
22
23
24
25
26
27
28
29
30
31
32
33
                        <p>{el.name}</p>
                        <div class="ratio ratio-16x9">
                            <iframe src={`https://www.youtube.com/embed/${el.key}`} title="YouTube video" allowfullscreen></iframe>
                        </div>
                    </div>
                ))
                : <div>예고편 정보가 존재하지 않습니다.</div>}
        </div>
    )
}

export default Video