10.1.0 • Published 1 year ago

react-youtube v10.1.0

Weekly downloads
141,873
License
MIT
Repository
github
Last release
1 year 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

@draftbit/corezwap-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-2625akello@hasura/console-oss@gatsby-mdx-suite/mdx-youtubereact-native-sdk-v2@hangindev/gatsby-theme-coursesrivigo-ui-commonsa@ingaia/ingaia-uisecondstep-marketingserasa-uiservermonitorcpen431react-social-media-embedreact-youtube-typescriptrex-coreuiductt-test-123@gem-sdk/componentseditor-homepagesemantic-card-sample@kilokilo/ewz-solar-map@kiranbandi/sask-cbme-dashboardggd-help-panel@m7eio/react-embedioc-liturgical-react@plasmicpkgs/react-youtube@piggytechng/component-libraryiport-next@podsite/gatsby-theme-podcast@quarkly/community-kitvibin-space-board@quintype/components@regionhalland/react-embedvonder-utils-inputvonder-utils-input-v2jrts-sanitykesho-uiwagcontent@royaltics/uispeedrunsfrontend-website-headlesssp-front-pagesp-frontendframework-entersol-web@jeremybanks/speedruns@milescreate/alliance-sanity-schematelerehab@mapgear/geoapps-ui-frameworktest-alias-3tired-hollow-libtired-hollow-lib-modsen@sirena/earth-common@siteone/atomsweb-tobi-2-appwegit-browser-clientingaia-uiui-kit-takeatinspace-widgetinspace-widget-testjitsi-meet-stepup@risecx/pose-estimation-component@rizna/componentstwreporter-reacttwreporter-react-article-componentsidyll-componentsigor-portfolio-gatsbyhpcbot@o2web.ca/museum-viewerstaircase-custom-componentsgatsby-theme-blog-sanitygatsby-theme-jamfire-conferencestargazer-lib@leuven2030/uigrandsettango-react-componentsgraphiconf@vip30/react-social-media-embedmicrosite-uinext-bootstrap@woodlanddirect/react-images-woodland@scandipwa/scandipwa@sentecacommerce-theme/clean-theme@sentecacommerce-theme/madame-coco-theme@sentecacommerce-theme/balevbio-theme@sentecacommerce-theme/byfar-showroom-theme
10.0.0-canary.2

1 year ago

10.1.0-canary.1

1 year ago

10.1.0

1 year ago

10.0.0

2 years ago

10.0.0-canary.1

2 years ago

9.0.3

2 years ago

9.0.2-canary.1

2 years ago

9.0.2-canary.2

2 years ago

9.0.2

2 years ago

9.0.1-canary.2

2 years ago

9.0.3-canary.1

2 years ago

9.0.1-canary.1

2 years ago

9.0.0-canary.1

2 years ago

8.3.0

2 years ago

9.0.1

2 years ago

9.0.0

2 years ago

8.3.0-canary.1

2 years ago

8.1.0

2 years ago

8.2.0-canary.2

2 years ago

8.2.0-canary.1

2 years ago

8.1.0-canary.1

2 years ago

8.2.1-canary.1

2 years ago

8.1.0-canary.2

2 years ago

8.0.0-canary.1

2 years ago

8.0.0-canary.2

2 years ago

8.0.0

2 years ago

8.2.1

2 years ago

8.2.0

2 years ago

7.14.0-canary.3

2 years ago

7.14.0-canary.2

2 years ago

7.14.0

2 years ago

7.14.0-canary.1

3 years ago

7.13.1-canary.4

3 years ago

7.13.1-canary.3

3 years ago

7.13.2-canary.1

3 years ago

7.13.1

3 years ago

7.13.1-canary.2

3 years ago

7.13.1-canary.1

3 years ago

7.13.0-canary.2

4 years ago

7.13.0

4 years ago

7.13.0-canary.1

4 years ago

7.12.1-canary.1

4 years ago

7.12.0-canary.3

4 years ago

7.12.0-canary.1

4 years ago

7.12.0-canary.2

4 years ago

7.12.0

4 years ago

7.11.3

4 years ago

7.11.3-canary.1

4 years ago

7.11.2

4 years ago

7.11.2-canary.1

4 years ago

7.11.1-canary.2

4 years ago

7.11.0-canary.2

4 years ago

7.11.0-canary.1

4 years ago

7.11.1-canary.1

4 years ago

7.10.0-canary.3

4 years ago

7.11.1

4 years ago

7.11.0

4 years ago

7.10.0-canary.2

4 years ago

7.10.0-canary.1

4 years ago

7.10.0

4 years ago

7.9.0

5 years ago

7.8.0

6 years ago

7.7.0

6 years ago

7.6.0

6 years ago

7.5.0

7 years ago

7.4.0

7 years ago

7.3.0

7 years ago

7.2.0

8 years ago

7.1.1

8 years ago

7.1.0

8 years ago

7.0.1

8 years ago

7.0.0

8 years ago

6.1.0

8 years ago

6.0.0

8 years ago

5.1.0

8 years ago

5.0.1

8 years ago

5.0.0

8 years ago

4.1.2

9 years ago

4.1.1

9 years ago

4.1.0

9 years ago

4.0.0

9 years ago

3.3.0

9 years ago

3.2.0

9 years ago

3.1.0

9 years ago

3.0.1

9 years ago

3.0.0

9 years ago

2.2.2

9 years ago

2.2.1

9 years ago

2.2.0

9 years ago

2.1.3

9 years ago

2.1.2

9 years ago

2.1.1

9 years ago

2.1.0

9 years ago

2.0.0

9 years ago

1.3.0

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.0.2

10 years ago

0.0.1

10 years ago