use Product Media
The useProductMedia hook fetches media items (images, videos, etc.) for a specific product.
Anchor to useProductMedia-parametersParameters
- Anchor to paramsparamsparamsUseProductMediaParamsUseProductMediaParamsrequiredrequired
UseProductMediaReturnsUseProductMediaReturns
UseProductMediaParams
- fetchPolicy
DataHookFetchPolicy - first
number - id
The product ID to fetch media for.
string - skip
boolean
DataHookFetchPolicy
'cache-first' | 'network-only'UseProductMediaReturns
- error
Error | null - fetchMore
() => Promise<void> - hasNextPage
boolean - loading
boolean - media
The product media returned from the query.
ProductMedia[] | null - refetch
() => Promise<void>
ProductMedia
{
id: string
image: ProductImage | null
mediaContentType: 'IMAGE'
alt: string | null
} | {
id: string
mediaContentType: 'MODEL_3D'
previewImage: ProductImage | null
sources: {
filesize: number
format: string
mimeType: string
url: string
}[]
alt: string | null
} | {
id: string
mediaContentType: 'VIDEO'
previewImage: ProductImage | null
sources: {
format: string
mimeType: string
url: string
width: number
height: number
}[]
alt: string | null
} | {
id: string
mediaContentType: 'EXTERNAL_VIDEO'
previewImage: ProductImage | null
embedUrl: string
alt: string | null
}ProductImage
- altText
string | null - height
number | null - id
string | null - sensitive
boolean | null - thumbhash
string | null - url
string - width
number | null
Examples
tsx
import {useProductMedia, Button} from '@shopify/shop-minis-react'
export default function MyComponent() {
const {media, loading, error, hasNextPage, loadMore} = useProductMedia({
id: 'gid://shopify/Product/123',
first: 10,
})
console.log({media, loading, error})
return (
<>
{/* Render media items here */}
{hasNextPage && (
<Button onClick={loadMore} disabled={loading}>
Load More Media
</Button>
)}
</>
)
}
Examples
Example code
tsx
import {useProductMedia, Button} from '@shopify/shop-minis-react' export default function MyComponent() { const {media, loading, error, hasNextPage, loadMore} = useProductMedia({ id: 'gid://shopify/Product/123', first: 10, }) console.log({media, loading, error}) return ( <> {/* Render media items here */} {hasNextPage && ( <Button onClick={loadMore} disabled={loading}> Load More Media </Button> )} </> ) }
Was this page helpful?