Skip to content

Conversation

@zirho
Copy link
Contributor

@zirho zirho commented Dec 6, 2022

I have code like this

This does not recognize the type of player since react-youtube depend on @types/youtube-player.
So I had to install @types/youtube-player dev dependency on my project to get type reference for the player object.

I think it does not make sense to add @types/youtube-player in dependencies of react-youtube so I am adding it as an instruction in README.md.

If you or anyone knows better way solving it. let me know, so that I can iterate on this PR.

OR you can make yours and close mine.

Thanks!

import { useState } from "react";
import YouTube, { YouTubePlayer } from "react-youtube";
import "./App.css";

function App() {
  const [player, setPlayer] = useState<YouTubePlayer>();

  return (
    <div className="App">
      <header className="App-header">
        <button
          onClick={() => {
            player?.getCurrentTime();
          }}
        >
          click
        </button>
        <YouTube
          videoId={"rAhXUkk6ppc"}
          opts={{
            width: 500,
            height: 300,
            playerVars: {
              autoplay: 0,
            },
          }}
          className="container"
          onReady={(event) => setPlayer(event.target)}
        />
      </header>
    </div>
  );
}

export default App;


@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 6, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit c6eeb78:

Sandbox Source
react-youtube-example Configuration

@zirho zirho requested a review from ruisaraiva19 December 6, 2022 21:15
@ruisaraiva19 ruisaraiva19 changed the title Instructions for typescript import docs: instructions for TypeScript import Dec 6, 2022
@ruisaraiva19 ruisaraiva19 merged commit d2d147a into tjallingt:canary Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants