Skip to content

Instantly share code, notes, and snippets.

@productioncoder
Last active November 10, 2018 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save productioncoder/e1bed923b840dc17e72354e076df5752 to your computer and use it in GitHub Desktop.
Save productioncoder/e1bed923b840dc17e72354e076df5752 to your computer and use it in GitHub Desktop.
Youtube in React: related videos
export function RelatedVideos(props) {
if (!props.videos || !props.videos.length) {
return <div className='related-videos'/>;
}
// safe because before we check if the array has at least one element
const nextUpVideo = props.videos[0];
const remainingVideos = props.videos.slice(1);
const relatedVideosPreviews = remainingVideos.map(relatedVideo => (
<VideoPreview video={relatedVideo}
key={relatedVideo.id}
pathname='/watch'
search={`?v=${relatedVideo.id}`}
horizontal={true}/>
));
return (
<div className='related-videos'>
<NextUpVideo video={nextUpVideo}/>
{relatedVideosPreviews}
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment