Issue with mapping array of images in React component
I can see the issue in your code! The problem is that you're not actually passing the image URL to your CardMedia component.
In your JSX, the CardMedia component is missing the image prop:
<CardMedia component="img" title={product.name} height='200' className="card-image"/>The fix: You need to add the image source. Since images is an array, you'll want to access the first image:
<CardMedia
component="img"
image={product.images[0]?.imageUrl}
title={product.name}
height='200'
className="card-image"
/>The ?. (optional chaining) prevents errors if the images array is empty or undefined.
Alternative approach using your urlFor helper:
Since you've already imported urlFor, you could also modify your query to return the full asset reference instead of just the URL:
*[_type == "product"] {
name,
images,
slug,
price
}Then use urlFor in your component:
<CardMedia
component="img"
image={product.images[0] ? urlFor(product.images[0]).url() : ''}
title={product.name}
height='200'
className="card-image"
/>The first approach (with asset->url in your query) is simpler and should work fine for your use case. The urlFor approach from @sanity/image-url is more powerful when you need to apply transformations like resizing, cropping, or format conversion (e.g., .width(400).format('webp')).
Either way, the key issue is that you're fetching the images correctly but not actually passing them to the CardMedia component's image prop!
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.