Skip to content

Commit 2cd3c24

Browse files
committed
initial commit
0 parents  commit 2cd3c24

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# react-hook-videojs
2+
3+
Due to how video.js mutates the DOM, integrating video.js with React can be a bit tricky. Especially if you want to support video.js component updates and correctly dispose of any old player.
4+
5+
React Hooks helps us package this quite nicely, and all you have to do to use this package is:
6+
7+
```
8+
import React from "react";
9+
import useVideoJS from "react-hook-videojs";
10+
11+
const App = () => {
12+
const videoUrl = "http://techslides.com/demos/sample-videos/small.mp4";
13+
const Player = useVideoJS({ sources: [{ src: videoUrl }] });
14+
return (
15+
<div className="App">
16+
<Player />
17+
</div>
18+
);
19+
};
20+
```
21+
22+
`useVideoJS` takes a single options argument, and passes it without modifications to video.js. See their [options reference](https://docs.videojs.com/tutorial-options.html) for further information.
23+
24+
Many thanks to Dan Abramov for helping me figure out some issues related to `useLayoutEffect` and video.js DOM manipulation.

index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export default (videoJsOptions) => {
2+
const videoNode = useRef(null);
3+
useLayoutEffect(
4+
() => {
5+
const player = videojs(videoNode.current, videoJsOptions, () => {
6+
console.log("onPlayerReady", this);
7+
});
8+
return () => {
9+
player.dispose();
10+
};
11+
},
12+
[JSON.stringify(videoJsOptions)]
13+
);
14+
return () => (
15+
<div data-vjs-player key={JSON.stringify(videoJsOptions)}>
16+
<video ref={videoNode} className="video-js" />
17+
</div>
18+
);
19+
};

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "react-hook-videojs",
3+
"version": "1.0.0",
4+
"description": "Easy React integration of Video.js using hooks.",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [
10+
"react",
11+
"hook",
12+
"hooks",
13+
"video.js",
14+
"videojs"
15+
],
16+
"peerDependencies": {
17+
"react": "^16.7.0",
18+
"react-dom": "^16.7.0",
19+
"video.js": "^7.0.0"
20+
},
21+
"author": "Jimmy Callin",
22+
"license": "MIT"
23+
}

0 commit comments

Comments
 (0)