Skip to content

Commit

Permalink
fix: Silence typescript errors and update VideoPlayer from class to f…
Browse files Browse the repository at this point in the history
…unction component and use hooks for ref and state mgmt
  • Loading branch information
runeb committed Feb 1, 2022
1 parent 636b705 commit b7069a3
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/components/VideoPlayer.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import React from 'react';
import React, {useEffect, useRef, useState} from 'react';
import videojs, { VideoJsPlayer, VideoJsPlayerOptions } from 'video.js';

export default class VideoPlayer extends React.Component<
VideoJsPlayerOptions,
any
> {
videoNode?: HTMLVideoElement;
player?: VideoJsPlayer;
componentDidMount() {
this.player = videojs(this.videoNode, this.props);
}
const VideoPlayer = (props:VideoJsPlayerOptions) => {
const videoNode = useRef<HTMLVideoElement>(null)
const [player, setPlayer] = useState<VideoJsPlayer>()

componentWillUnmount() {
if (this.player) {
this.player.dispose();
useEffect(() => {
if (videoNode.current) {
setPlayer(videojs(videoNode.current, props))
}
}
return () => player?.dispose()
}, [videoNode])

render() {
return (
<div>
<link
Expand All @@ -27,14 +21,11 @@ export default class VideoPlayer extends React.Component<
<div data-vjs-player style={{ marginBottom: '16px' }}>
<video
className="video-js vjs-16-9 vjs-big-play-centered"
ref={node => {
if (node) {
this.videoNode = node;
}
}}
ref={videoNode}
></video>
</div>
</div>
);
}
}

export default VideoPlayer

0 comments on commit b7069a3

Please sign in to comment.