Hi, I'm working on a project and I'm trying to create a Netflix clone site. My goal is to show the cover titles of the movies, on a Homepage main banner. to do this I created the following three files inside my folder:
import axios from "axios";
const instance = axios.create({
baseURL: "https://api.themoviedb.org/3"
});
export default instance;
const API_KEY = "___MY API____";
const requests = {
fetchTrending: `/trending/all/week?api_key=${API_KEY}&language=en-US`,
fetchNetflixOriginals: `/discover/tv?api_key=${API_KEY}&with_networks=213`,
fetchComedyMovies: `/discover/movie?api_key=${API_KEY}&with_genres=35`,
fetchHorrorMovies: `/discover/movie?api_key=${API_KEY}&with_genres=27`,
fetchRomanceMovies: `/discover/movie?api_key=${API_KEY}&with_genres=10749`,
fetchDocumentaries: `/discover/movie?api_key=${API_KEY}&with_genres=99`,
};
export default requests;
import React, { useEffect, useState } from 'react';
import "./Banner.css";
import axios from "./axios"
import requests from "./Requests";
function Banner() {
const [movie, setMovie] = useState([]);
useEffect(() => {
async function fetchData() {
const request = await axios.get(requests.fetchNetflixOriginals);
setMovie(
request.data.results[
Math.floor(Math.random() * request.data.results.lenght - 1)
]
);
return requests;
}
fetchData();
}, [])
console.log(movie);
The problem is that when I try to do the "console.log" it returns a 404 error and an empty array.
The background of the banner goes from black to completely white and no films appear on my banner.
This makes me assume that there is some error in the code or some problem in the API. Could someone please check the code and help me figure out where the error is? Thank you!
Can't find a movie or TV show? Login to create it.
Want to rate or add this item to a list?
Not a member?
Reply by superboy97
on July 22, 2021 at 10:45 AM
There is at least one error : "lenght" need to be replaced by "length".
Reply by Travis Bell
on July 23, 2021 at 5:02 PM
For coding specific issues like this, I usually recommend heading over to Stack Overflow as you can ask platform and library specific question to users who are familiar with it. I'm not familiar with Axios so I won't be much help.