Socket
Socket
Sign inDemoInstall

@u-wave/react-youtube

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@u-wave/react-youtube

YouTube player component for React.


Version published
Weekly downloads
3K
increased by29.47%
Maintainers
1
Weekly downloads
 
Created
Source

@u-wave/react-youtube

YouTube player component for React.

Install - Usage - Demo - Component API - Hook API

Install

npm install @u-wave/react-youtube

Usage

Demo - Demo source code

import YouTube from '@u-wave/react-youtube';

<YouTube
  video="x2to0hs"
  autoplay
/>

<YouTube />

The <YouTube /> component renders an iframe and attaches the YouTube player to it. It supports all the same options as the useYouTube hook, plus a few to configure the iframe. If you need to do more with the iframe than this component provides, consider using the useYouTube hook directly.

Props

NameTypeDefaultDescription
idstringDOM ID for the player element.
classNamestringCSS className for the player element.
styleobjectInline style for container element.
videostringAn 11-character string representing a YouTube video ID..
widthnumber, stringWidth of the player element.
heightnumber, stringHeight of the player element.
hoststringhttps://www.youtube.comYouTube host to use: 'https://www.youtube.com' or 'https://www.youtube-nocookie.com'.
originstringThe YouTube API will usually default this value correctly. It is exposed for completeness.
https://developers.google.com/youtube/player_parameters#origin
pausedboolPause the video.
autoplayboolfalseWhether the video should start playing automatically.
https://developers.google.com/youtube/player_parameters#autoplay
showCaptionsboolfalseWhether to show captions below the video.
https://developers.google.com/youtube/player_parameters#cc_load_policy
controlsbooltrueWhether to show video controls.
https://developers.google.com/youtube/player_parameters#controls
disableKeyboardboolfalseIgnore keyboard controls.
https://developers.google.com/youtube/player_parameters#disablekb
allowFullscreenbooltrueWhether to display the fullscreen button.
https://developers.google.com/youtube/player_parameters#fs
langstringThe player's interface language. The parameter value is an ISO 639-1 two-letter language code or a fully specified locale.
https://developers.google.com/youtube/player_parameters#hl
annotationsbooltrueWhether to show annotations on top of the video.
https://developers.google.com/youtube/player_parameters#iv_load_policy
startSecondsnumberTime in seconds at which to start playing the video.
https://developers.google.com/youtube/player_parameters#start
endSecondsnumberTime in seconds at which to stop playing the video.
https://developers.google.com/youtube/player_parameters#end
modestBrandingboolfalseRemove most YouTube logos from the player.
https://developers.google.com/youtube/player_parameters#modestbranding
playsInlineboolfalseWhether to play the video inline on iOS, instead of fullscreen.
https://developers.google.com/youtube/player_parameters#playsinline
showRelatedVideosbooltrueWhether to show related videos after the video is over.
https://developers.google.com/youtube/player_parameters#rel
volumenumberThe playback volume, as a number between 0 and 1.
mutedboolWhether the video's sound should be muted.
playbackRatenumberPlayback speed.
https://developers.google.com/youtube/iframe_api_reference#setPlaybackRate
onReadyfunctionSent when the YouTube player API has loaded.
onErrorfunctionSent when the player triggers an error.
onCuedfunctionSent when the video is cued and ready to play.
onBufferingfunctionSent when the video is buffering.
onPlayingfunctionSent when playback has been started or resumed.
onPausefunctionSent when playback has been paused.
onEndfunctionSent when playback has stopped.
onStateChangefunction
onPlaybackRateChangefunction
onPlaybackQualityChangefunction

useYouTube(container, options)

Create a YouTube player at container. container must be a ref object.

Returns the YT.Player object, or null until the player is ready.

import { useYouTube } from '@u-wave/react-youtube';

function Player() {
  const container = useRef(null);
  const player = useYouTube(container, {
    video: 'x2to0hs',
    autoplay: true,
  });
  console.log(player?.getVideoUrl());
  return <div ref={container} />;
}

Options

NameTypeDefaultDescription
videostringAn 11-character string representing a YouTube video ID..
widthnumber, stringWidth of the player element.
heightnumber, stringHeight of the player element.
hoststringhttps://www.youtube.comYouTube host to use: 'https://www.youtube.com' or 'https://www.youtube-nocookie.com'.
originstringThe YouTube API will usually default this value correctly. It is exposed for completeness.
https://developers.google.com/youtube/player_parameters#origin
pausedboolPause the video.
autoplayboolfalseWhether the video should start playing automatically.
https://developers.google.com/youtube/player_parameters#autoplay
showCaptionsboolfalseWhether to show captions below the video.
https://developers.google.com/youtube/player_parameters#cc_load_policy
controlsbooltrueWhether to show video controls.
https://developers.google.com/youtube/player_parameters#controls
disableKeyboardboolfalseIgnore keyboard controls.
https://developers.google.com/youtube/player_parameters#disablekb
allowFullscreenbooltrueWhether to display the fullscreen button.
https://developers.google.com/youtube/player_parameters#fs
langstringThe player's interface language. The parameter value is an ISO 639-1 two-letter language code or a fully specified locale.
https://developers.google.com/youtube/player_parameters#hl
annotationsbooltrueWhether to show annotations on top of the video.
https://developers.google.com/youtube/player_parameters#iv_load_policy
startSecondsnumberTime in seconds at which to start playing the video.
https://developers.google.com/youtube/player_parameters#start
endSecondsnumberTime in seconds at which to stop playing the video.
https://developers.google.com/youtube/player_parameters#end
modestBrandingboolfalseRemove most YouTube logos from the player.
https://developers.google.com/youtube/player_parameters#modestbranding
playsInlineboolfalseWhether to play the video inline on iOS, instead of fullscreen.
https://developers.google.com/youtube/player_parameters#playsinline
showRelatedVideosbooltrueWhether to show related videos after the video is over.
https://developers.google.com/youtube/player_parameters#rel
volumenumberThe playback volume, as a number between 0 and 1.
mutedboolWhether the video's sound should be muted.
playbackRatenumberPlayback speed.
https://developers.google.com/youtube/iframe_api_reference#setPlaybackRate
onReadyfunctionSent when the YouTube player API has loaded.
onErrorfunctionSent when the player triggers an error.
onCuedfunctionSent when the video is cued and ready to play.
onBufferingfunctionSent when the video is buffering.
onPlayingfunctionSent when playback has been started or resumed.
onPausefunctionSent when playback has been paused.
onEndfunctionSent when playback has stopped.
onStateChangefunction
onPlaybackRateChangefunction
onPlaybackQualityChangefunction
  • react-dailymotion - A Dailymotion component with a similar declarative API.
  • @u-wave/react-vimeo - A Vimeo component with a similar declarative API.
  • react-youtube - A widely-used YouTube component. Its API matches the YouTube iframe API more closely, and it doesn't support prop-based volume/playback changes.

License

MIT

Keywords

FAQs

Package last updated on 03 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc