Skip to content

Commit 8081cbc

Browse files
FEAT: customize fallback through props for lazy loading (cookpete#1133)
* FEAT: customize fallback through props for lazy loading * README.md updated * linter issues fixed * Partial revert to keep changes minimal Co-authored-by: Pete Cook <pete@cookpete.com>
1 parent 27f1bcf commit 8081cbc

4 files changed

Lines changed: 6 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Prop | Description | Default
9393
`playsinline` | Applies the `playsinline` attribute where supported | `false`
9494
`pip` | Set to `true` or `false` to enable or disable [picture-in-picture mode](https://developers.google.com/web/updates/2018/10/watch-video-using-picture-in-picture)<br/>&nbsp;&nbsp;Only available when playing file URLs in [certain browsers](https://caniuse.com/#feat=picture-in-picture) | `false`
9595
`stopOnUnmount` | If you are using `pip` you may want to use `stopOnUnmount={false}` to continue playing in picture-in-picture mode even after ReactPlayer unmounts | `true`
96+
`fallback` | Element or component to use as a fallback if you are using lazy loading | `null`
9697
`wrapper` | Element or component to use as the container element | `div`
9798
`playIcon` | Element or component to use as the play icon in light mode
9899
`config` | Override options for the various players, see [config prop](#config-prop)

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export interface ReactPlayerProps {
9898
pip?: boolean;
9999
stopOnUnmount?: boolean;
100100
light?: boolean | string;
101+
fallback?: React.ReactNode;
101102
wrapper?: any;
102103
config?: Config;
103104
onReady?(player: ReactPlayer): void;

src/ReactPlayer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ export const createReactPlayer = (players, fallback) => {
162162
}
163163

164164
render () {
165-
const { url, style, width, height, wrapper: Wrapper } = this.props
165+
const { url, style, width, height, fallback, wrapper: Wrapper } = this.props
166166
const { showPreview } = this.state
167167
const attributes = this.getAttributes(url)
168168
return (
169169
<Wrapper ref={this.references.wrapper} style={{ ...style, width, height }} {...attributes}>
170-
<UniversalSuspense fallback={null}>
170+
<UniversalSuspense fallback={fallback}>
171171
{showPreview
172172
? this.renderPreview(url)
173173
: this.renderActivePlayer(url)}

src/props.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const propTypes = {
1919
stopOnUnmount: bool,
2020
light: oneOfType([bool, string]),
2121
playIcon: node,
22+
fallback: node,
2223
wrapper: oneOfType([
2324
string,
2425
func,
@@ -106,6 +107,7 @@ export const defaultProps = {
106107
pip: false,
107108
stopOnUnmount: true,
108109
light: false,
110+
fallback: null,
109111
wrapper: 'div',
110112
config: {
111113
soundcloud: {

0 commit comments

Comments
 (0)