Video
The Video component renders a video for the Storefront API's Video object.
The component outputs a video element. You can customize this component using passthrough props.
Anchor to propsProps
- Anchor to datadatadataPartialDeep<VideoType, {recurseIntoArrays: true}>PartialDeep<VideoType, {recurseIntoArrays: true}>requiredrequired
An object with fields that correspond to the Storefront API's Video object.
- Anchor to previewImageOptionspreview
Image Optionspreview Image Options LoaderParamsLoaderParams An object of image size options for the video's
. Usesto generate theposterURL.- Anchor to sourcePropssource
Propssource Props HTMLAttributes<HTMLSourceElement> & { 'data-testid'?: string; }HTMLAttributes<HTMLSourceElement> & { 'data-testid'?: string; } Props that will be passed to the
videoelement'ssourcechildren elements.
LoaderParams
- crop
The URL param that controls the cropping region
Crop - height
The URL param that controls height
number - src
The base URL of the image
string - width
The URL param that controls width
number
Crop
'center' | 'top' | 'bottom' | 'left' | 'right'Examples
import {Video} from '@shopify/hydrogen';
export default function MyProductVideo({products}) {
const firstMediaElement = products.edges[0].node.media.edges[0].node;
if (firstMediaElement.__typename === 'Video') {
return <Video data={firstMediaElement} />;
}
}
Examples
Example code
JavaScript
import {Video} from '@shopify/hydrogen'; export default function MyProductVideo({products}) { const firstMediaElement = products.edges[0].node.media.edges[0].node; if (firstMediaElement.__typename === 'Video') { return <Video data={firstMediaElement} />; } }TypeScript
import {Video} from '@shopify/hydrogen'; import type {ProductConnection} from '@shopify/hydrogen/storefront-api-types'; export default function MyProductVideo({ products, }: { products: ProductConnection; }) { const firstMediaElement = products.edges[0].node.media.edges[0].node; if (firstMediaElement.__typename === 'Video') { return <Video data={firstMediaElement} />; } }
Was this page helpful?