MovieComming.js 1.07 KB
Newer Older
1
2
3
4
5
6
7
8
import { useState, useEffect } from 'react'
import movieApi from "../apis/movie.api.js"
import MovieCard from "./MovieCard/index.js"
import catchErrors from '../utils/catchErrors.js'

const MovieComming = () => {
    const [TMDB_UpComming_Data, setTMDB_UpComming_Data] = useState([])
    const [error, setError] = useState("")
Jiwon Yoon's avatar
Jiwon Yoon committed
9
    const category = "upcoming"
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

    useEffect(() => {
        getTMDB_UpComming()
    }, [])

    async function getTMDB_UpComming() {
        try {
            setError("")
            const response = await movieApi.getfromTM(category)
            setTMDB_UpComming_Data([...response])
        } catch (error) {
            catchErrors(error, setError)
        }
    }

    return (
        <>
            {TMDB_UpComming_Data.length !== 0 ?
                <div className="row row-cols-1 row-cols-md-4 g-4">
                    <MovieCard list={TMDB_UpComming_Data} />
                </div>
                : <h2 className="text-white text-center my-5">영화정보를 로딩할  없습니다.</h2>
            }
        </>
    )
}

export default MovieComming