Using what you learned about React Lists & Keys, you'll build a streaming platform that displays movies and TV series. This assignment will test your understanding of:
.map()// Use this exact configuration
const TMDB_API_KEY = '2ca22f700bb9eff7e814bfbe16ba6831'
const BASE_URL = 'https://api.themoviedb.org/3'
const IMAGE_BASE_URL = 'https://image.tmdb.org/t/p/'
const POSTER_SIZE = 'w500'
const BACKDROP_SIZE = 'original'// For popular movies
const moviesURL = `${BASE_URL}/movie/popular?api_key=${TMDB_API_KEY}&language=en-US&page=1`
// For popular TV series
const seriesURL = `${BASE_URL}/tv/popular?api_key=${TMDB_API_KEY}&language=en-US&page=1`// For poster images
const posterURL = `${IMAGE_BASE_URL}${POSTER_SIZE}${movie.poster_path}`
// For backdrop images (optional)
const backdropURL = `${IMAGE_BASE_URL}${BACKDROP_SIZE}${movie.backdrop_path}`function StreamFlix() {
const [activeTab, setActiveTab] = useState('movies');
const [movies, setMovies] = useState([]);
const [series, setSeries] = useState([]);
const [loading, setLoading] = useState(true);
// Your code here
}// Function to fetch movies
const fetchMovies = async () => {
try {
const response = await fetch(moviesURL);
const data = await response.json();
setMovies(data.results || []);
} catch (error) {
console.error('Error fetching movies:', error);
setMovies([]);
}
};
// Function to fetch TV series
const fetchSeries = async () => {
// Similar structure to fetchMovies
};useEffect(() => {
const loadData = async () => {
setLoading(true);
await Promise.all([fetchMovies(), fetchSeries()]);
setLoading(false);
};
loadData();
}, []);// Example for movies list
{movies.length === 0 ? (
<p>No movies found</p>
) : (
<div className="movies-grid">
{movies.map(movie => (
<div key={movie.id} className="movie-card">
<img src={`${IMAGE_BASE_URL}${POSTER_SIZE}${movie.poster_path}`} alt={movie.title} />
<h3>{movie.title}</h3>
<p>⭐ {movie.vote_average}</p>
<p>📅 {movie.release_date}</p>
</div>
))}
</div>
)}If you finish early, try adding:
movie.id or series.id as keysThis assignment reinforces:
.map()Your assignment will be evaluated on:
Good luck! Remember to apply everything you learned about lists and keys today. This is your chance to build something awesome! 🚀