@lizzie
To add YouTube videos in React.js, follow these steps:
- Install the react-youtube library by running the following command:
npm install react-youtube
- Import the necessary components from the library in your React component:
import ReactPlayer from 'react-youtube';
- Define the YouTube video ID or URL in your React component's state or props:
state = {
videoId: 'VIDEO_ID_OR_URL'
};
- Render the YouTube video using the ReactPlayer component within your React component's render method:
render() {
return (
);
}
Replace 'VIDEO_ID_OR_URL'
with the YouTube video ID or URL you want to display.
That's it! You have successfully added a YouTube video in React.js using the react-youtube
library.