Skip to content

Frameworks

Vega Player is a standard Custom Element, so it works wherever HTML works. Every attribute is also a property that reflects back to the attribute, which is what modern frameworks use when they pass props to custom elements. Values set before the script has loaded are applied when the element upgrades.

import { useEffect, useRef } from 'react';
import './vega-player.js';
export function Trailer({ src }) {
const ref = useRef(null);
useEffect(() => {
const onEnded = () => console.log('ended');
ref.current.addEventListener('vega-player:ended', onEnded);
return () => ref.current?.removeEventListener('vega-player:ended', onEnded);
}, []);
return <vega-player ref={ref} src={src} color-primary="#ff6a2b" show-playback-rate />;
}

The player renders on the client. During server rendering the tag is output as-is and upgrades as soon as the script loads; set aspect-ratio so the page reserves the right space in the meantime.