1.2.7 • Published 3 years ago

react-lite-yt-embed v1.2.7

Weekly downloads
279
License
MIT
Repository
github
Last release
3 years ago

React Lite YouTube Embed

React component version of lite-youtube-embed scaffolded with tsdx, which focus on visual performance, rendering just like the real thing but much faster.

FOSSA Status Download

npm.io

Quick Start

Install

Please use version at least above @1.2.1, version below that is experimental and therefore may cause some runtime error.

react-lite-yt-embed

$ yarn add react-lite-yt-embed

or

$ npm install react-lite-yt-embed

Sandbox Example

codesandbox

Overview

Features 🎉

  • Preconnect YouTube domain while mouseover
  • Preload thumbnail image to improve user experience
  • WebP support, and fallback to jpg if the browser not support it
  • Provides many props which can customize frame behaviors
  • Lazy load support
  • Render fast, improve your web's performance

Introduction

'react-lite-yt-embed' is a react component version of popular package lite-youtube-embed, which can use in React project including SSR and CSR project. It renders just like the real iframe but way much faster.

Why is it faster than normal iframe ?

WebP Support (support after version @1.2.4)

'react-lite-yt-embed' support WebP image format, which is generally 25% - 35% smaller than jpg image, so the network request time will also decrease, making your web app render even faster.

If you use some browsers that not totally support WebP, for example, Safari, 'react-lite-yt-embed' will fallback the image to jpg automatically.

You can see WebP browser support here.

Basic Usage

import { LiteYoutubeEmbed } from 'react-lite-yt-embed';

// In your react component
<>
  <LiteYoutubeEmbed id={id}> {/* ID of YouTube video */}
  {/* You can add more props, see the description below. */}
  {/* You can also give the iframe an outer container */}
</>

Component Props

propsrequireddefault valueTypeDescription
idtruenonestringThe unique id of the youtube video
defaultPlayfalsefalsebooleanSet defaultPlay as true will directly show youtube iframe
isPlaylistfalsefalsebooleanIf you want to play playlist, set this as true and pass the playlist id
noCookiefalsetruebooleanUse "https://www.youtube-nocookie.com" as path or "https://www.youtube.com"
mutefalsetruebooleanSet the video is mute or not.
paramsfalse{}Object<string, string>Query string params (autoplay and mute are default query string, you do not have to set them), the value have to be a string type.
isMobilefalsefalsebooleanUse in mobile device or not.
mobileResolutionfalse'hqdefault''hqdefault' | 'sddefault' | 'maxresdefault'You can specify the resolution of the thumbnail image on the phone (default is hqdefault, which is a lower resolution).
desktopResolutionfalse'maxresdefault''hqdefault' | 'sddefault' | 'maxresdefault'You can specify the resolution of the thumbnail image on the desktop (default is maxresdefault, which is the highest resolution).
lazyImagefalsefalsebooleanIf true, set the img loading attribute to 'lazy', default is undefined.
imageAltTextfalse"YouTube's thumbnail for this video."stringYou can specify an alternative text description for the thumbnail image for accessibility purposes.
iframeTitlefalse"YouTube video."stringYou can specify a title for the iframe containing the video for accessibility purposes.

Run on local development environment

  • Clone the repo
  • npm install | yarn install
  • Make your change or contribution
  • npm run build (in root folder)
  • cd in example folder & run npm install
  • npm run build (in example folder)
  • npm run start (in example folder)
  • visit localhost:1234 in the browser

Roadmap (Welcome contribution)

  • Testing
  • CI/CD pipeline

License

FOSSA Status

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.49

3 years ago

1.0.51

3 years ago

1.0.50

3 years ago

1.0.54

3 years ago

1.0.53

3 years ago

1.0.52

3 years ago

1.0.48

3 years ago

1.0.47

3 years ago

1.0.46

3 years ago

1.0.45

3 years ago

1.0.44

3 years ago

1.0.43

3 years ago

1.0.42

4 years ago

1.0.41

4 years ago

1.0.40

4 years ago

1.0.39

4 years ago

1.0.38

4 years ago

1.0.37

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.22

4 years ago

1.0.23

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago