Model Viewercomponent
The component renders a 3D model (with the
model-viewer
custom element) for the Storefront API's Model3d object. The model-viewer
custom element is lazily downloaded through a dynamically-injected <script type='module'>
tag when the component is rendered. ModelViewer is using version
1.21.1
of the library.
Anchor to propsProps
- Anchor to datadataPartialDeep<Model3d, {recurseIntoArrays: true}>required
An object with fields that correspond to the Storefront API's Model3D object.
- Anchor to onErroronError(event: Event) => void
The callback to invoke when the 'error' event is triggered. Refer to error in the
documentation .- Anchor to onLoadonLoad(event: Event) => void
The callback to invoke when the
load
event is triggered. Refer to load in thedocumentation .- Anchor to onPreloadonPreload(event: Event) => void
The callback to invoke when the 'preload' event is triggered. Refer to preload in the
documentation .- Anchor to onModelVisibilityonModelVisibility(event: Event) => void
The callback to invoke when the 'model-visibility' event is triggered. Refer to model-visibility in the
documentation .- Anchor to onProgressonProgress(event: Event) => void
The callback to invoke when the 'progress' event is triggered. Refer to progress in the
documentation .- Anchor to onArStatusonArStatus(event: Event) => void
The callback to invoke when the 'ar-status' event is triggered. Refer to ar-status in the
documentation .- Anchor to onArTrackingonArTracking(event: Event) => void
The callback to invoke when the 'ar-tracking' event is triggered. Refer to ar-tracking in the
documentation .- (event: Event) => void
The callback to invoke when the 'quick-look-button-tapped' event is triggered. Refer to quick-look-button-tapped in the
documentation .- Anchor to onCameraChangeonCameraChange(event: Event) => void
The callback to invoke when the 'camera-change' event is triggered. Refer to camera-change in the
documentation .- Anchor to onEnvironmentChangeonEnvironmentChange(event: Event) => void
The callback to invoke when the 'environment-change' event is triggered. Refer to environment-change in the
documentation .- Anchor to onPlayonPlay(event: Event) => void
The callback to invoke when the 'play' event is triggered. Refer to play in the
documentation .- Anchor to onPauseonPause(event: Event) => void
The callback to invoke when the 'pause' event is triggered. Refer to pause in the
documentation .- Anchor to onSceneGraphReadyonSceneGraphReady(event: Event) => void
The callback to invoke when the 'scene-graph-ready' event is triggered. Refer to scene-graph-ready in the
documentation .
ModelViewerBaseProps
- data
An object with fields that correspond to the Storefront API's [Model3D object](https://shopify.dev/api/storefront/2024-01/objects/model3d).
PartialDeep<Model3d, {recurseIntoArrays: true}>
- onError
The callback to invoke when the 'error' event is triggered. Refer to [error in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-error).
(event: Event) => void
- onLoad
The callback to invoke when the `load` event is triggered. Refer to [load in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-load).
(event: Event) => void
- onPreload
The callback to invoke when the 'preload' event is triggered. Refer to [preload in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-preload).
(event: Event) => void
- onModelVisibility
The callback to invoke when the 'model-visibility' event is triggered. Refer to [model-visibility in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-modelVisibility).
(event: Event) => void
- onProgress
The callback to invoke when the 'progress' event is triggered. Refer to [progress in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-progress).
(event: Event) => void
- onArStatus
The callback to invoke when the 'ar-status' event is triggered. Refer to [ar-status in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-events-arStatus).
(event: Event) => void
- onArTracking
The callback to invoke when the 'ar-tracking' event is triggered. Refer to [ar-tracking in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-events-arTracking).
(event: Event) => void
- onQuickLookButtonTapped
The callback to invoke when the 'quick-look-button-tapped' event is triggered. Refer to [quick-look-button-tapped in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-events-quickLookButtonTapped).
(event: Event) => void
- onCameraChange
The callback to invoke when the 'camera-change' event is triggered. Refer to [camera-change in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-stagingandcameras-events-cameraChange).
(event: Event) => void
- onEnvironmentChange
The callback to invoke when the 'environment-change' event is triggered. Refer to [environment-change in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-lightingandenv-events-environmentChange).
(event: Event) => void
- onPlay
The callback to invoke when the 'play' event is triggered. Refer to [play in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-animation-events-play).
(event: Event) => void
- onPause
The callback to invoke when the 'pause' event is triggered. Refer to [pause in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-animation-events-pause).
(event: Event) => void
- onSceneGraphReady
The callback to invoke when the 'scene-graph-ready' event is triggered. Refer to [scene-graph-ready in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-scenegraph-events-sceneGraphReady).
(event: Event) => void
{
/** An object with fields that correspond to the Storefront API's [Model3D object](https://shopify.dev/api/storefront/2024-01/objects/model3d). */
data: PartialDeep<Model3d, {recurseIntoArrays: true}>;
/** The callback to invoke when the 'error' event is triggered. Refer to [error in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-error). */
onError?: (event: Event) => void;
/** The callback to invoke when the `load` event is triggered. Refer to [load in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-load). */
onLoad?: (event: Event) => void;
/** The callback to invoke when the 'preload' event is triggered. Refer to [preload in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-preload). */
onPreload?: (event: Event) => void;
/** The callback to invoke when the 'model-visibility' event is triggered. Refer to [model-visibility in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-modelVisibility). */
onModelVisibility?: (event: Event) => void;
/** The callback to invoke when the 'progress' event is triggered. Refer to [progress in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-events-progress). */
onProgress?: (event: Event) => void;
/** The callback to invoke when the 'ar-status' event is triggered. Refer to [ar-status in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-events-arStatus). */
onArStatus?: (event: Event) => void;
/** The callback to invoke when the 'ar-tracking' event is triggered. Refer to [ar-tracking in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-events-arTracking). */
onArTracking?: (event: Event) => void;
/** The callback to invoke when the 'quick-look-button-tapped' event is triggered. Refer to [quick-look-button-tapped in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-events-quickLookButtonTapped). */
onQuickLookButtonTapped?: (event: Event) => void;
/** The callback to invoke when the 'camera-change' event is triggered. Refer to [camera-change in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-stagingandcameras-events-cameraChange). */
onCameraChange?: (event: Event) => void;
/** The callback to invoke when the 'environment-change' event is triggered. Refer to [environment-change in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-lightingandenv-events-environmentChange). */
onEnvironmentChange?: (event: Event) => void;
/** The callback to invoke when the 'play' event is triggered. Refer to [play in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-animation-events-play). */
onPlay?: (event: Event) => void;
/** The callback to invoke when the 'pause' event is triggered. Refer to [pause in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-animation-events-pause). */
onPause?: (event: Event) => void;
/** The callback to invoke when the 'scene-graph-ready' event is triggered. Refer to [scene-graph-ready in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-scenegraph-events-sceneGraphReady). */
onSceneGraphReady?: (event: Event) => void;
}
Example code
examples
Example code
description
I am the default example
JavaScript
import {ModelViewer} from '@shopify/hydrogen-react'; export default function MyProductModel({products}) { const firstMediaElement = products.nodes[0].media.nodes[0]; if (firstMediaElement.__typename === 'Model3d') { return <ModelViewer data={firstMediaElement} />; } }
TypeScript
import {ModelViewer} from '@shopify/hydrogen-react'; import type {ProductConnection} from '@shopify/hydrogen-react/storefront-api-types'; export default function MyProductModel({ products, }: { products: ProductConnection; }) { const firstMediaElement = products.nodes[0].media.nodes[0]; if (firstMediaElement.__typename === 'Model3d') { return <ModelViewer data={firstMediaElement} />; } }