Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(guides): add basic ReactJS integration example #3972

Merged
merged 4 commits into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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`.