MovieChart.js 1.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { useState, useEffect } from 'react'
import MovieCard from './MovieCard/index.js'
import movieApi from '../apis/movie.api.js'
import catchErrors from '../utils/catchErrors.js'

const MovieChart = () => {
    const [TMDB_TopRated_Data, setTMDB_TopRated_Data] = useState([])
    const [error, setError] = useState("")
    const category = "popular"

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

    async function getTMDB_TopRated() {
        try {
            setError("")
Kim, Subin's avatar
Kim, Subin committed
18
            const data = await movieApi.getListByCategoryfromDB(category)
19
20
21
22
23
24
25
26
27
28
29
30
            setTMDB_TopRated_Data([...data])
        } catch (error) {
            catchErrors(error, setError)
        }
    }

    return (
        <>
            {TMDB_TopRated_Data.length !== 0 ?
                <div className="row row-cols-1 row-cols-md-4 g-4">
                    <MovieCard list={TMDB_TopRated_Data} />
                </div>
Kim, Subin's avatar
Kim, Subin committed
31
                : <h2 className="text-white text-center p-5"> </h2>
32
33
34
35
36
37
            }
        </>
    )
}

export default MovieChart