Showing
1 changed file
with
20 additions
and
1 deletions
| @@ -44,5 +44,24 @@ export const useTMDB = function() { | @@ -44,5 +44,24 @@ export const useTMDB = function() { | ||
| 44 | } | 44 | } |
| 45 | }; | 45 | }; |
| 46 | 46 | ||
| 47 | - return { fetchPopularMovies, searchMovies } | 47 | + /** |
| 48 | + * Fetch movie details by id. | ||
| 49 | + * @param id | ||
| 50 | + */ | ||
| 51 | + const fetchMovieDetails = async (id: number) => { | ||
| 52 | + try { | ||
| 53 | + const response = await fetch( | ||
| 54 | + `${apiUrl}/movie/${id}?api_key=${apiKey}&language=fr-FR`, | ||
| 55 | + ); | ||
| 56 | + if (!response.ok) { | ||
| 57 | + console.error("An error occurred when fetching movie details:"); | ||
| 58 | + } else { | ||
| 59 | + return await response.json(); | ||
| 60 | + } | ||
| 61 | + } catch (error) { | ||
| 62 | + console.error("Error fetching details:", error); | ||
| 63 | + } | ||
| 64 | + }; | ||
| 65 | + | ||
| 66 | + return { fetchPopularMovies, searchMovies, fetchMovieDetails } | ||
| 48 | } | 67 | } |
-
Please register or login to post a comment