Skip to content

Commit

Permalink
docs(guides): Add a basic ReactJS guide and update the FAQ (#3972)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Bouquillon authored and brandonocasey committed Jan 26, 2017
1 parent 7b0d738 commit 05b39fe
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/guides/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* [Q: Does video.js have any support for advertisement integrations?](#q-does-videojs-have-any-support-for-advertisement-integrations)
* [Q: Can video.js be required in node.js?](#q-can-videojs-be-required-in-nodejs)
* [Q: Does video.js work with webpack?](#q-does-videojs-work-with-webpack)
* [Q: Does video.js work with react?](#q-does-videojs-work-with-react)

## Q: What is video.js?

Expand Down Expand Up @@ -269,6 +270,12 @@ Yes! Please [submit an issue or open a pull request][pr-issue-question] if this

Yes! Please [submit an issue or open a pull request][pr-issue-question] if this does not work.

Be sure to use `require('!style-loader!css-loader!video.js/dist/video-js.css')` to inject video.js CSS.

## Q: Does video.js work with react?

Yes! See [ReactJS integration example](./guides/react.md).

[plugin-guide]: plugins.md

[install-guide]: http://videojs.com/getting-started/
Expand Down
2 changes: 2 additions & 0 deletions docs/guides/player-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ Coming soon...

### React

See [ReactJS integration example](./react.md)

### Ember

### Angular
55 changes: 55 additions & 0 deletions docs/guides/react.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# video.js and ReactJS integration

Here's a basic ReactJS player implementation.

It just instantiates the video.js player on `componentDidMount` and destroys it on `componentWillUnmount`.

```jsx
import React from 'react';
import videojs from 'video.js'

export default class VideoPlayer extends React.Component {
componentDidMount() {
// instantiate video.js
this.player = videojs(this.videoNode, this.props, function onPlayerReady() {
console.log('onPlayerReady', this)
});
}

// destroy player on unmount
componentWillUnmount() {
if (this.player) {
this.player.dispose()
}
}

// wrap the player in a div with a `data-vjs-player` attribute
// so videojs won't create additional wrapper in the DOM
// see https://github.com/videojs/video.js/pull/3856
render() {
return (
<div data-vjs-player>
<video ref={ node => this.videoNode = node } className="video-js"></video>
</div>
)
}
}
```

You can then use it like this:

```jsx
// see https://github.com/videojs/video.js/blob/master/docs/guides/options.md
const videoJsOptions = {
autoPlay: true,
controls: true,
sources: [{
src: '/path/to/video.mp4',
type: 'video/mp4'
}]
}

return <VideoPlayer { ...videoJsOptions } />
```

Dont forget to include the video.js CSS, located at `video.js/dist/video-js.css`.

0 comments on commit 05b39fe

Please sign in to comment.