MovieChart.js 1.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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("")
19
            const data = await movieApi.getListByCategoryfromDB(category)
20
21
22
23
24
25
26
27
28
29
30
31
32
            console.log("sdad==", data)
            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>
33
                : <h2 className="text-white text-center p-5"> </h2>
34
35
36
37
38
39
            }
        </>
    )
}

export default MovieChart