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

Conversation

revolunet
Copy link
Contributor

Description

Just some doc for a clean ReactJS integration

Specific Changes proposed

add guides/react.md

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
    • Change has been verified in an actual browser (Chome, Firefox, IE)
    • Unit Tests updated or fixed
    • Docs/guides updated
    • Example created (starter template on JSBin)
  • Reviewed by Two Core Contributors

Copy link
Contributor

@brandonocasey brandonocasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks for the PR. I made a few small comments, once those are all resolved we should be able to get this in.

@@ -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.

Use `require('!style-loader!css-loader!video.js/dist/video-js.css')` to inject video.js CSS.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add "Be sure to" on the front of this sentence to make it a bit more readable.

import videojs from 'video.js'

// this loads video.js CSS using webpack loaders
require('!style-loader!css-loader!video.js/dist/video-js.css')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may want to exclude this line and the comment above as it is more webpack specific


Here's a basic ReactJS player implementation.

It just instantiate the video.js player on `componentDidMount` and destroy it on `componentWillUnmount`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • instantiate instantiates
  • destroy destroys

}
```

You can then use it like this :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the extra space before :

@revolunet
Copy link
Contributor Author

Thanks. i added a footnote in react.md about webpack+css.

Copy link
Contributor

@brandonocasey brandonocasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Can you rebase this? The FAQ was moved back into docs/guides folder and it's causing a conflict.

export default class VideoPlayer extends React.Component {
componentDidMount() {
// get the <video> DOM node
const videoNode = ReactDOM.findDOMNode(this).querySelector('video');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on <video ref={(c) => { this.videoNode = c; }} /> instead of ReactDOM?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what is "best" way, but you're right, using ref is more straightforward


If you use webpack, you can embed video.js CSS like this:

`require('!style-loader!css-loader!video.js/dist/video-js.css')`
Copy link
Member

@chemoish chemoish Jan 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this line more confusing than anything.

If they are using Webpack, then they already know about loaders, otherwise they won't get very far.

If they already know about loaders, then they must also know the power they have to transform files (https://webpack.js.org/guides/code-splitting-css/).

You don't need to have Webpack to include styles and recommending the inline approach might be less than ideal?

(probably fine in the Webpack section)

2️⃣ cents.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, now that the tooling is stable and mainstream (create-react-app, nwb...) i'm not sure that everyone master webpack loaders config. also the path to the CSS is not obvious so i think its worth mentionning ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for people using browserify or something else, we could also mention alternatives ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about just mentioning that you can find the css file at that path and not mention bundler specific stuff?
We also link to it in the package.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, removed the mention to webpack 😢

@fgarcia
Copy link

fgarcia commented Jan 25, 2017 via email

@@ -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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is tricky and needs more background. First it assumes webpack is being used, but that's the most common case with React anyways. Then style-loader and css-loader are extra packages which must be installed too

It would be better to say that React people should have two concerns:

  • Safe DOM manipulation
  • Loading Video.js CSS

and that line, is an example of how the solution might be done (in many, but not all cases)

@brandonocasey brandonocasey merged commit 05b39fe into videojs:master Jan 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants