Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.3 kB
2
Indexable
Never
import React, { useEffect, useState } from "react";
import { useParams } from "react-router-dom";

const Detail = () => {
    const { movieId } = useParams();
    const [movieDetails, setMovieDetails] = useState(null);

    useEffect(() => {
        const fetchMovieDetails = async () => {
            const options = {
                method: 'GET',
                headers: {
                    accept: 'application/json',
                    Authorization: 'Bearer YOUR_TOKEN'
                }
            };

            try {
                const response = await fetch(`https://api.themoviedb.org/3/movie/${movieId}?language=fr-FR`, options);
                const data = await response.json();
                setMovieDetails(data);
            } catch (err) {
                console.error(err);
            }
        };

        fetchMovieDetails();
    }, [movieId]);

    // Gestion de l'affichage conditionnel en fonction de movieDetails
    if (movieDetails === null) {
        return <div>Chargement des détails du film...</div>;
    }

    return (
        <div className="detail">
            <h1>{movieDetails.title}</h1>
            {/* Autres détails du film ici */}
        </div>
    );
}

export default Detail;
Leave a Comment