App.js
1 2 3 4 5 6 7 8 9 10 11 12 |
import React from "react"; import "./styles.css"; import YoutubeEmbed from "./YoutubeEmbed"; export default function App() { return ( <div className="App"> <h1>Youtube Embed</h1> <YoutubeEmbed embedId="rokGy0huYEA" /> </div> ); } |
App.css
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
.video-responsive { overflow: hidden; padding-bottom: 56.25%; position: relative; height: 0; } .video-responsive iframe { left: 0; top: 0; height: 100%; width: 100%; position: absolute; } |
YoutubeEmbed.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import React from "react"; import PropTypes from "prop-types"; const YoutubeEmbed = ({ embedId }) => ( <div className="video-responsive"> <iframe width="853" height="480" src={`https://www.youtube.com/embed/${embedId}`} frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen title="Embedded youtube" /> </div> ); YoutubeEmbed.propTypes = { embedId: PropTypes.string.isRequired }; export default YoutubeEmbed; |