Skip to content

Commit

Permalink
chore: updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
gojutin committed Mar 9, 2022
1 parent 58668c4 commit 59462f0
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# react-hook-youtube

![npm](https://img.shields.io/npm/v/react-hook-youtube?style=social)
![npm bundle size](https://img.shields.io/bundlephobia/minzip/react-hook-youtube?style=social)
![NPM](https://img.shields.io/npm/l/react-hook-youtube?style=social)

A custom React hook for easily working with the [Youtube Player API for iframe Embeds](https://developers.google.com/youtube/iframe_api_reference).

## Usage
Expand All @@ -15,7 +19,7 @@ npm install react-hook-youtube
Basic Example

```tsx
import React from "react";
import * as React from "react";
import { useYoutubePlayer } from "react-hook-youtube";

export default App = () => {
Expand All @@ -30,28 +34,42 @@ export default App = () => {
Advanced Example

```tsx
import React from "react";
import * as React from "react";
import { useYoutubePlayer, player } from "react-hook-youtube";

export default App = () => {
const { YoutubePlayer } = useYoutubePlayer({
videoId: "KRvv0QdruMQ",
height: "390",
width: "640",
playerVars: {
playsinline: 1,
},
events: {
onReady: (event) => {
console.log("OnReady event fired.", event);
},
onStateChange: (event) => {
console.log("OnStateChange event fired.", event);
},
onPlaybackQualityChange: (event) => {
console.log("onPlaybackQualityChange event fired.", event);
},
onPlaybackRateChange: (event) => {
console.log("OnPlaybackRateChange event fired.", event);
},
onError: (event) => {
console.log("onError event fired.", event);
},
onApiChange: (event) => {
console.log("onApiChange event fired.", event);
},
},
});

return (
<div>
<YoutubePlayer />
<YoutubePlayer className="my-video-player" id="my-unique-id" />
<section>
<button onClick={player.pauseVideo}>Pause</button>
<button onClick={player.stopVideo}>Stop</button>
Expand All @@ -63,3 +81,9 @@ export default App = () => {
);
};
```

Please refer to the [Youtube Player API Reference](https://developers.google.com/youtube/iframe_api_reference) for all of the available player config and player control options. This package also ships with TypeScript type definitions so you can just let Intellisense guide you.

[Youtube Type Definitions](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/youtube/index.d.ts)

TODO: Document playlist usage

0 comments on commit 59462f0

Please sign in to comment.