Skip to content

Commit

Permalink
Default to eager component loading
Browse files Browse the repository at this point in the history
  • Loading branch information
sistrall committed Oct 23, 2024
1 parent 9c78c6a commit ad9d6ec
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 112 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- `<VideoPlayer>` component now is eager by default (the lazy version is available via `import VideoPlayer from 'react-datocms/video-player/lazy';`)

## [2.0.1] - 2022-01-05

### Added

- `layout` property to Image component

### Changed

- Default layout is now `intrinsic`, so the image the image will scale the dimensions down for smaller viewports, but maintain the original dimensions for larger viewports
Expand Down
22 changes: 19 additions & 3 deletions docs/video-player.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [Usage](#usage)
- [Example](#example)
- [Props](#props)
- [Lazy version](#lazy-version)
- [Advanced usage: the `useVideoPlayer` hook](#advanced-usage-the-usevideoplayer-hook)
- [Example](#example-1)

Expand All @@ -21,18 +22,16 @@ To stream videos, DatoCMS partners with MUX, a video CDN that serves optimized s
## Out-of-the-box features

- Offers optimized streaming so smartphones and tablets don’t request desktop-sized videos
- Lazy loads the video component and the video to be played to speed initial page load and save bandwidth
- Holds the video position and size so your page doesn’t jump while the player loads
- Uses blur-up technique to show a placeholder of the video while it loads
- Optionally lazy loads the video component and the video to be played to speed initial page load and save bandwidth

## Installation

```
npm install --save react-datocms @mux/mux-player-react
```

`@mux/mux-player-react` is a [peer dependency](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#peerdependencies) for `react-datocms`: so you're expected to add it in your project.

## Usage

1. Import `VideoPlayer` from `react-datocms` and use it in your app
Expand Down Expand Up @@ -110,6 +109,23 @@ Compared to the `<MuxPlayer />`, **some prop default values are different** on `

All the other props are forwarded to the `<MuxPlayer />` component that is used internally.

## Lazy version

For an optimized bundle, we provide a lazy version too. To use it, you need to change
the way to import the component. From:

```js
import { VideoPlayer } from 'react-datocms';
````

to:

```js
import VideoPlayer from 'react-datocms/video-player/lazy';
```

The lazy version is based on `React.lazy()` method.

## Advanced usage: the `useVideoPlayer` hook

Even though we try our best to make the `<VideoPlayer />` suitable and easy to use for most normal use cases, there are situations where you may need to leverage the `<MuxPlayer />` directly (let's suppose you wrote your special wrapper component around the `<MuxPlayer />` and you need a bunch of props to pass). If that's the case, fill free to use the hook we provide: `useVideoPlayer`.
Expand Down
174 changes: 105 additions & 69 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ad9d6ec

Please sign in to comment.