Last active
April 21, 2021 15:21
-
-
Save jbowa/3049c2ba77b7d619260d29ca2e2db110 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {useEffect} from 'react' | |
import Plyr, {SourceInfo, Options} from 'plyr' | |
import 'plyr/dist/plyr.css' | |
const usePlyr = (id: string, sources: SourceInfo, opts?: Options) => { | |
useEffect(() => { | |
const el = document.getElementById(id) | |
const player = new Plyr(el, opts) | |
player.source = sources | |
return () => player.destroy() | |
}, [sources, opts]) | |
} | |
export default usePlyr | |
// use | |
const MediaBlock = () => { | |
const sources = { | |
type: 'video', | |
sources: [{src: sourceUrl}] | |
} | |
usePlyr('plyr', sources, options) | |
render = ( | |
<Container> | |
<video id='plyr' /> | |
</Container> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment