Download netflix-clone-using-react/src/components/row.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/netflix-clone-using-react/src/components/row.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/netflix-clone-using-react/src/components/row.js
-
curl -L -o row.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/netflix-clone-using-react/src/components/row.js
1.83 kB
| import React, { useState, useEffect } from 'react'; | |
| import axios from '../axios'; | |
| import "./row.css"; | |
| import YouTube from "react-youtube"; | |
| import movieTrailer from "movie-trailer"; | |
| const base_url = "https://image.tmdb.org/t/p/original/"; | |
| function Row({ title, fetchUrl, isLargeRow }) { | |
| const [movies, setMovies] = useState([]); | |
| const [trailerUrl, setTrailerUrl] = useState(""); | |
| useEffect(() => { | |
| async function fetchData(){ | |
| const requests = await axios.get(fetchUrl); | |
| setMovies(requests.data.results); | |
| return requests; | |
| } | |
| fetchData(); | |
| }, [fetchUrl]); | |
| const opts = { | |
| height: "390", | |
| width: "100%", | |
| playVars: { | |
| // https://developers.google.com/youtube/player_parameters | |
| autoplay: 1, | |
| }, | |
| }; | |
| const handleClick = (movie) => { | |
| if(trailerUrl) { | |
| setTrailerUrl(''); | |
| } else { | |
| movieTrailer(movie?.name || "").then(url => { | |
| const urlParams = new URLSearchParams(new URL(url).search); | |
| setTrailerUrl(urlParams.get('v')); | |
| }) | |
| .catch(error => console.log(error)); | |
| } | |
| }; | |
| return ( | |
| <div className="row" > | |
| <h2>{title}</h2> | |
| <div className="row_posters"> | |
| {movies.map(movie => ( | |
| <img | |
| key={movie.id} | |
| onClick={() => handleClick(movie)} | |
| className={`row_poster ${isLargeRow && "row_posterLarge"}`} | |
| src={`${base_url}${isLargeRow ? movie.poster_path : movie.backdrop_path}`} alt={movie.name} /> | |
| ))} | |
| </div> | |
| {trailerUrl && <YouTube videoId={trailerUrl} opts={opts} />} | |
| </div> | |
| ) | |
| } | |
| export default Row | |