10.1.0 • Published 2 years ago

react-youtube v10.1.0

Weekly downloads
141,873
License
MIT
Repository
github
Last release
2 years ago

Release Tests Example

react-youtube

Simple React component acting as a thin layer over the YouTube IFrame Player API

Features

Installation

NPM

npm install react-youtube

Yarn

yarn add react-youtube

PNPM

pnpm add react-youtube

Usage

<YouTube
  videoId={string}                  // defaults -> ''
  id={string}                       // defaults -> ''
  className={string}                // defaults -> ''
  iframeClassName={string}          // defaults -> ''
  style={object}                    // defaults -> {}
  title={string}                    // defaults -> ''
  loading={string}                  // defaults -> undefined
  opts={obj}                        // defaults -> {}
  onReady={func}                    // defaults -> noop
  onPlay={func}                     // defaults -> noop
  onPause={func}                    // defaults -> noop
  onEnd={func}                      // defaults -> noop
  onError={func}                    // defaults -> noop
  onStateChange={func}              // defaults -> noop
  onPlaybackRateChange={func}       // defaults -> noop
  onPlaybackQualityChange={func}    // defaults -> noop
/>

For convenience it is also possible to access the PlayerState constants through react-youtube: YouTube.PlayerState contains the values that are used by the YouTube IFrame Player API.

Example

// js
import React from 'react';
import YouTube from 'react-youtube';

class Example extends React.Component {
  render() {
    const opts = {
      height: '390',
      width: '640',
      playerVars: {
        // https://developers.google.com/youtube/player_parameters
        autoplay: 1,
      },
    };

    return <YouTube videoId="2g811Eo7K8U" opts={opts} onReady={this._onReady} />;
  }

  _onReady(event) {
    // access to player in all event handlers via event.target
    event.target.pauseVideo();
  }
}
// ts
import React from 'react';
import YouTube, { YouTubeProps } from 'react-youtube';

function Example() {
  const onPlayerReady: YouTubeProps['onReady'] = (event) => {
    // access to player in all event handlers via event.target
    event.target.pauseVideo();
  }

  const opts: YouTubeProps['opts'] = {
    height: '390',
    width: '640',
    playerVars: {
      // https://developers.google.com/youtube/player_parameters
      autoplay: 1,
    },
  };

  return <YouTube videoId="2g811Eo7K8U" opts={opts} onReady={onPlayerReady} />;
}

Controlling the player

You can access & control the player in a way similar to the official api:

The API component will pass an event object as the sole argument to each of those functions the event handler props. The event object has the following properties:

  • The event's target identifies the video player that corresponds to the event.
  • The event's data specifies a value relevant to the event. Note that the onReady event does not specify a data property.

License

MIT

zwap-qrcode-frontendcreative-gallery-shonpdivanru-uioct-pwa-ui@nib-components/content-video@nib-components/content-video-panelbeedeez-webapp-pro@telus-uds/components-allium-web@teko-builder/builder-base-componentsjitsi-meet-rn@mcxbr/livereact-native-jitsi-meet-libgumroad-api-tester-webapp@infinitebrahmanuniverse/nolb-react-yreact-vrwjitsi-meet-react-native-rocket@everything-registry/sub-chunk-2625akellotango-react-componentstest-alias-3wagcontentweb-tobi-2-appwegit-browser-clientwemixplay-uitelerehabspeedrunsvonder-utils-inputvonder-utils-input-v2vibin-space-board@clutch-marketplace/youtube-player@devbookhq/docusaurus-code-video-plugin@cparram/bm-i360-shared@draftbit/core@boring-ui/embed@royaltics/uijitsi-meet-stepupjitsi-fmtechjrts-sanityiport-nextkesho-uisrcoresp-front-pagesp-frontendstargazer-libstaircase-custom-componentsspacklevideotwreporter-reacttwreporter-react-article-componentsui-kit-takeattired-hollow-libtired-hollow-lib-modsen@ameyanaik/active-info@aurocraft/builder@aurocraft/builder-elements@alya-mirror/asm-youtube-addon@blocks/kit@climb-creative/wttb-components@codementor/ui-kityear-end-recapyoutube-bg-reactyoutube-jukeboxyoutube-playlistsyoutube-locations-formwebmotors.catalogo.ui@hangindev/gatsby-theme-courses@hasura/console-oss@edu-tosel/design@gatsby-mdx-suite/mdx-youtube@gem-sdk/components@ingaia/ingaia-ui@leuven2030/ui@m7eio/react-embed@mapgear/geoapps-ui-framework@milescreate/alliance-sanity-schema@kilokilo/ewz-solar-map@kiranbandi/sask-cbme-dashboard@jeremybanks/speedruns@quintype/components@quarkly/community-kit@scandipwa/scandipwa@regionhalland/react-embed@risecx/pose-estimation-component@rizna/components@plasmicpkgs/react-youtube@podsite/gatsby-theme-podcast@piggytechng/component-library@nudodesigns/noxy-ecommerce-website@o2web.ca/museum-viewer@sirena/earth-common@sentecacommerce-theme/byfar-showroom-theme@sentecacommerce-theme/byfar-theme@sentecacommerce-theme/clean-theme@sentecacommerce-theme/balevbio-theme@sentecacommerce-theme/madame-coco-theme@siteone/atomsmkhancha_myformsmodsen-themeforest-ensome-hollowmickberber.pagemicrosite-uiotrm
10.0.0-canary.2

2 years ago

10.1.0-canary.1

2 years ago

10.1.0

2 years ago

10.0.0

3 years ago

10.0.0-canary.1

3 years ago

9.0.3

3 years ago

9.0.2-canary.1

3 years ago

9.0.2-canary.2

3 years ago

9.0.2

3 years ago

9.0.1-canary.2

3 years ago

9.0.3-canary.1

3 years ago

9.0.1-canary.1

3 years ago

9.0.0-canary.1

3 years ago

8.3.0

3 years ago

9.0.1

3 years ago

9.0.0

3 years ago

8.3.0-canary.1

3 years ago

8.1.0

3 years ago

8.2.0-canary.2

3 years ago

8.2.0-canary.1

3 years ago

8.1.0-canary.1

3 years ago

8.2.1-canary.1

3 years ago

8.1.0-canary.2

3 years ago

8.0.0-canary.1

3 years ago

8.0.0-canary.2

3 years ago

8.0.0

3 years ago

8.2.1

3 years ago

8.2.0

3 years ago

7.14.0-canary.3

3 years ago

7.14.0-canary.2

3 years ago

7.14.0

3 years ago

7.14.0-canary.1

4 years ago

7.13.1-canary.4

4 years ago

7.13.1-canary.3

4 years ago

7.13.2-canary.1

4 years ago

7.13.1

4 years ago

7.13.1-canary.2

4 years ago

7.13.1-canary.1

4 years ago

7.13.0-canary.2

5 years ago

7.13.0

5 years ago

7.13.0-canary.1

5 years ago

7.12.1-canary.1

5 years ago

7.12.0-canary.3

5 years ago

7.12.0-canary.1

5 years ago

7.12.0-canary.2

5 years ago

7.12.0

5 years ago

7.11.3

5 years ago

7.11.3-canary.1

5 years ago

7.11.2

5 years ago

7.11.2-canary.1

5 years ago

7.11.1-canary.2

5 years ago

7.11.0-canary.2

5 years ago

7.11.0-canary.1

5 years ago

7.11.1-canary.1

5 years ago

7.10.0-canary.3

5 years ago

7.11.1

5 years ago

7.11.0

5 years ago

7.10.0-canary.2

5 years ago

7.10.0-canary.1

5 years ago

7.10.0

5 years ago

7.9.0

6 years ago

7.8.0

7 years ago

7.7.0

7 years ago

7.6.0

7 years ago

7.5.0

8 years ago

7.4.0

8 years ago

7.3.0

8 years ago

7.2.0

9 years ago

7.1.1

9 years ago

7.1.0

9 years ago

7.0.1

9 years ago

7.0.0

9 years ago

6.1.0

9 years ago

6.0.0

9 years ago

5.1.0

9 years ago

5.0.1

9 years ago

5.0.0

9 years ago

4.1.2

10 years ago

4.1.1

10 years ago

4.1.0

10 years ago

4.0.0

10 years ago

3.3.0

10 years ago

3.2.0

10 years ago

3.1.0

10 years ago

3.0.1

10 years ago

3.0.0

10 years ago

2.2.2

10 years ago

2.2.1

10 years ago

2.2.0

10 years ago

2.1.3

10 years ago

2.1.2

10 years ago

2.1.1

10 years ago

2.1.0

10 years ago

2.0.0

10 years ago

1.3.0

10 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.3

11 years ago

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago