This project has multiple issues, that have really been causing me issues. Im going to post the API key for now incase anyone needs to try to accomplish this aslo, then ill be requesting a new API key from the API host.
So my issue is, Ive called a movie database API which gives me 20 trending movies of the week. I set that data to a state I called "trending". NO problem. Then I mapped trending and go a list of the movies ID#'s. I saved these to a state called "movieId". These id's are important because I need them for the final call to a different endpoint. it needs the moviesID to return data that gives me a link to where someone can buy or watch the movie. The list of links to each indvidual movie ID's provider is what my main goal is. I need these links so I can assign each movie it's provider link so the user can click the movie picture and be led to where they can watch the movie. I dont need to accomplish that yet though. FOr now, I just need the Links. Im trying this with the code below but all I get is infinite loops, type errors saying I US.link is not valid etc. Im doing something wrong but I dont know what it is, please help!
Here is the link to the sandbox ----> React Sandbox Project
import "./styles.css";
import React, { useEffect, useState } from "react";
export default function App() {
const [trending, setTrending] = useState([]);
const [movieId, setMovieId] = useState("");
const [link, setLink] = useState("");
// set trending to get the movies data.
//set movieID to get the movie ID's
//set link to get the providerlink that belongs to each movieID.
useEffect(() => {
const trendUrl =
"https://api.themoviedb.org/3/trending/movie/week?api_key=fde5ddeba3b7dec3fc1f51852ca0fb95";
fetch(trendUrl)
.then((response) => response.json())
.then((data) => {
setTrending(data.results);
})
.catch((error) => {
console.log("Error!! Data interupted!:", error);
});
}, []);
const Collection = () => {
trending.map((item) => setMovieId(item.id));
};
Collection();
function Linked() {
const url = `https://api.themoviedb.org/3/movie/${movieId}/watch/providers?api_key=fde5ddeba3b7dec3fc1f51852ca0fb95`;
fetch(url)
.then((res) => res.json())
.then((res) => console.log(res.results.US.link));
//Gives movie ID and adds it to properlink
}
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
</div>
);
}
```