A lightweight React component for HTML5 videos with MP4/WebM support
npm install react-create-html-video!component-preview-compressed
!npm
!downloads
!license
A lightweight React component that programmatically generates and plays an HTML element with a clean, reusable API. This library does not rely on CSS-in-JS, with styles are intentionally kept minimal. Created with Typescript support.
``console`
npm install react-create-html-video
1. Built for modern React with support for Typescript
2. A lightweight API surface that is easy to understand
3. Helps render a native HTML
`javascript`
export type TReactCreateHTMLVideo = {
mp4: string;
webm: string;
};
`javascript`
"peerDependencies": {
"react": ">=18",
"react-dom": ">=18"
}
1. Detects browser support using HTMLVideoElement.canPlayTypenull
2. Prefers MP4 if supported
3. Falls back to WebM if MP4 is unavailable
4. Disables video rendering on Internet Explorer
5. Returns when no supported format is available
`javascript
/ node modules /
import { ReactCreateHTMLVideo } from "react-create-html-video";
/ module /
function UIComponent() {
return (
{/ make sure your parent container is positioned: relative, imagine here min-height of 100vh /}
/ exports /
export default UIComponent;
`
``
PASS src/video-component/test/index.test.tsx
RCHV Test Suite:
โ renders null when videoSource is null
โ renders video container when videoSource is provided
โ renders video element with correct attributes
โ sets video src to the videoSource from useVideo hook
โ passes correct props to useVideo hook
โ memoizes component and does not re-render with same props
โ renders video element inside parent container
โ updates when videoSource changes
โ returns null when videoSource is falsy
โ renders only one video element
``
-----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
index.tsx | 100 | 100 | 100 | 100 |
-----------|---------|----------|---------|---------|-------------------
๐ฏ Note: Release(s) 1.4.x has fixed issues related to react-dedup. It was found that inspite of being a react client side component, an error related to `Cannot read properties of undefined (reading 'ReactCurrentDispatcher')`` was coming up. You can now install this package directly. If issues still persist, please do raise a github issue along with screenshots and comments for me to work on.
Contributions, suggestions, and improvements are welcome.
Feel free to open issues or pull requests.
Like this project? Support it with a github star, it would mean a lot to me! Cheers and Happy Coding.