Hej, I am creating slideshow module in sanity, but I get this error: ```An error occured: Invalid item type: "[object Object]". Default array input can only contain objects...

1 replies
Last updated: Jan 6, 2021
Hej, I am creating slideshow module in sanity, but I get this error:
An error occured: Invalid item type: "[object Object]". Default array input can only contain objects (for now)
Check your browser's JavaScript console for details.
Here is my fields

export default {
  title: 'Slideshow Module',
  name: 'slideshowModule',
  type: 'array',
  hidden: true,
  of: [
    {
      type: 'object',
      fields: [
        {
          name: 'headline',
          title: 'Headline',
          type: 'localeString'
        },
        {
          name: 'subtitle',
          title: 'Subtitle',
          type: 'localeString'
        },
        {
          name: 'images',
          title: 'Images',
          type: 'imageModule'
        }
      ]
    }
  ]
}
AI Update

I can see the issue! When you define an inline object within an array's of property, you need to give that object a name property. The error "Invalid item type: [object Object]" occurs because Sanity can't properly identify the object type without a name.

Here's your corrected schema:

export default {
  title: 'Slideshow Module',
  name: 'slideshowModule',
  type: 'array',
  hidden: true,
  of: [
    {
      type: 'object',
      name: 'slide', // Add this name property
      fields: [
        {
          name: 'headline',
          title: 'Headline',
          type: 'localeString'
        },
        {
          name: 'subtitle',
          title: 'Subtitle',
          type: 'localeString'
        },
        {
          name: 'images',
          title: 'Images',
          type: 'imageModule'
        }
      ]
    }
  ]
}

The key fix is adding name: 'slide' to your inline object definition. According to the array fields documentation, each member type in an array needs to be properly identified, and inline objects require a name property for this identification.

Alternative approach (cleaner and more reusable):

You can also define the slide object as a separate schema type and reference it:

// schemas/slide.js
export default {
  name: 'slide',
  type: 'object',
  fields: [
    {
      name: 'headline',
      title: 'Headline',
      type: 'localeString'
    },
    {
      name: 'subtitle',
      title: 'Subtitle',
      type: 'localeString'
    },
    {
      name: 'images',
      title: 'Images',
      type: 'imageModule'
    }
  ]
}

// schemas/slideshowModule.js
export default {
  title: 'Slideshow Module',
  name: 'slideshowModule',
  type: 'array',
  hidden: true,
  of: [{type: 'slide'}]
}

This approach makes your schema more maintainable and allows you to reuse the slide object type elsewhere if needed. Either solution will resolve the "Invalid item type" error you're seeing!

This is because
slideshowModule
 is an
array
 and you use it in a rich text field which is also an array. The way to solve it is to make the
slideshowModule
 an
object
 with one
array
 type for the images.
I'd check out this guide:
https://www.sanity.io/blog/creating-custom-content-blocks-gutenberg-vs-sanity

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.

Was this answer helpful?