Generate experiences with Puck AI
Read docs
CloudAPI referenceplugin-assetsComponents<AssetMedia>

<AssetMedia>

Puck Assets is in early access. Request access.

Render the value of an asset field as an image or video.

import { AssetMedia } from "@puckeditor/plugin-assets";
 
const config = {
  components: {
    Hero: {
      fields: { image: { type: "asset" } },
      render: ({ image }) =>
        image ? (
          <AssetMedia
            src={image.src}
            alt={image.alt}
            mediaType={image.mediaType}
          />
        ) : null,
    },
  },
};

Props

ParamExampleTypeStatus
srcsrc: image.srcStringRequired
altalt: image.altString-
aspectRatioaspectRatio: "16x9""16x9" | "1x1" | Number-
classNameclassName: "hero-image"String-
loadingloading: "eager""lazy" | "eager"-
mediaTypemediaType: image.mediaTypeString-
sizessizes: "50vw"String-

Required props

src

The asset’s URL. Use the src property of the asset field value.

Optional props

alt

The accessible description for the asset. Use the alt property of the asset field value.

aspectRatio

The shape the asset fills ("16x9", "1x1", or a number). Defaults to the image’s own shape.

className

The element’s CSS class.

loading

When to load the asset. "lazy" waits until the asset is near the screen. Defaults to "lazy".

mediaType

The asset’s media type. Defines how the asset should be rendered. Must be a valid image or video MIME type string.

sizes

The image’s sizes attribute. Defaults to "100vw".