|
23 | 23 |
|
24 | 24 | ### Migrating to ReactPlayer `v2.0`
|
25 | 25 |
|
26 |
| -ReactPlayer `v2.0` removes single player imports in favour of lazy loading players. Support for `preload` has also been removed, plus some other changes. See [`MIGRATING.md`](/MIGRATING.md) for information. |
| 26 | +ReactPlayer `v2.0` changes single player imports and adds lazy loading players. Support for `preload` has also been removed, plus some other changes. See [`MIGRATING.md`](/MIGRATING.md) for information. |
27 | 27 |
|
28 | 28 | ### Usage
|
29 | 29 |
|
30 | 30 | ```bash
|
31 |
| -npm install react-player |
| 31 | +npm install react-player # or yarn add react-player |
32 | 32 | ```
|
33 | 33 |
|
34 | 34 | ```jsx
|
35 | 35 | import React from 'react'
|
36 | 36 | import ReactPlayer from 'react-player'
|
37 | 37 |
|
38 |
| -const App = () => ( |
39 |
| - <ReactPlayer url='https://www.youtube.com/watch?v=ysz5S6PUM-U' /> |
40 |
| -) |
| 38 | +// Render a YouTube video player |
| 39 | +<ReactPlayer url='https://www.youtube.com/watch?v=ysz5S6PUM-U' /> |
41 | 40 | ```
|
42 | 41 |
|
43 |
| -If your build system supports `import()` statements, use `react-player/lazy` to lazy load the appropriate player for the `url` you pass in. This will add several `reactPlayer` chunks to your bundle, but reduce your main bundle size. |
| 42 | +By default, ReactPlayer supports [many different types](#supported-media) of `url`. If you only ever use one type, use imports such as `react-player/youtube` to reduce your bundle size. See [config keys](#config-prop) for all player keys. |
44 | 43 |
|
45 | 44 | ```jsx
|
46 | 45 | import React from 'react'
|
47 |
| -import ReactPlayer from 'react-player/lazy' |
| 46 | +import ReactPlayer from 'react-player/youtube' |
48 | 47 |
|
49 | 48 | // Only loads the YouTube player
|
50 |
| -const App = () => ( |
51 |
| - <ReactPlayer url='https://www.youtube.com/watch?v=ysz5S6PUM-U' /> |
52 |
| -) |
| 49 | +<ReactPlayer url='https://www.youtube.com/watch?v=ysz5S6PUM-U' /> |
| 50 | +``` |
| 51 | + |
| 52 | +If your build system supports `import()` statements, use `react-player/lazy` to lazy load the appropriate player for the `url` you pass in. This adds several `reactPlayer` chunks to your output, but reduces your main bundle size. |
| 53 | + |
| 54 | +```jsx |
| 55 | +import React from 'react' |
| 56 | +import ReactPlayer from 'react-player/lazy' |
| 57 | + |
| 58 | +// Lazy load the YouTube player |
| 59 | +<ReactPlayer url='https://www.youtube.com/watch?v=ysz5S6PUM-U' /> |
53 | 60 | ```
|
54 | 61 |
|
55 | 62 | Demo page: [`https://cookpete.com/react-player`](https://cookpete.com/react-player)
|
|
0 commit comments