Youtube player in React

 Command to install

====================================================================


npm i react-youtube


https://www.npmjs.com/package/react-youtube


Import in Js file

====================================================================


import YouTube from "react-youtube";



In Js File

====================================================================


 const opts = {

    height: "390",

    width: "640",

    playerVars: {

      autoplay: 1,

    },

  };

  function _onReady(e) {

    // access to player in all event handlers via event.target

    e.target.pauseVideo();

  }

 

In render of Js file

====================================================================

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


Comments