Search code examples
reactjssanity

How to add and display multiple images with sanity.io?


I've tried to add more images in my sanity project without any result. I've add a schema for that.

{
  name: 'gallery',
  title: 'Gallery',
  type: 'array',
  of: [{ type: 'image', 
  options: {
    hotspot: true,
  },}]
 }

But when I console.log the result of the post where I upload more images I get only _ref and _type and no URL like in the mainImage.

How can I display multiple images? Thanks


Solution

  • to get the url you need to fetch data like that :

    client.fetch(`*[_type == 'post']{
        _id,
        title,
        gallery[]{
            asset->{
                url
            }
        }]
    }`)......