A pretty good and effective way to create a video placeholder from Youtube or Vimeo using a high-res image. If you don't know, when an
<iframe> is rendered from browser, it blocks its parse because it isn't a non-blocking script. This isn't so good to your user, no?. With this react component, the
<iframe> just will be loaded when the user click on play.
Installing this component is very easy and it has just one dependency: React. So, you have a lot of options to do that:
- Using NPM ~the quickest way~
$ npm install --save react-video
- Using Bower
$ bower install --save react-video
- Or if you want to download the lastest release and put in your website, it will work too!
NOTICE: You need just one thing to make the component work. Put the base component style at the
<header> tag. If you don't wanna use the
.css extension, you can get the
.scss extension at the folder
Then you're done! 😸
Using the component is simpler than installing. See an example with browserify to bundle your script:
var Video = ;// Video from YoutubeReact;// Video from VimeoReact;
videoId is optional, so you can use it or not. If you don't pass the property, the component will select your type of video based on your id.
To handle errors when something happens, like your video can't be loaded, you can pass a callback with a prop
onError in the component:
window.ReactVideo (or just
/** @jsx React.DOM */var Video = ReactVideo;
Behind the Scene
There are some things that you should know about the component. The first one is the structure created inside by the component if you wish to stylize it.
So, the semantic HTML structure will be something like this:
This is a very simple structure to stylize however you want. So, if you are lost, don't panic, there is a real functional example that you can follow.
For more details, check out the API below.
||none||no||The video ID|
||yes||no||Callback function if the video can't be loaded|
Anyone can help make this project better - check out the Contributing guide!
See the License file.