👋 Next.js Conf 2024: Come build, party, run, and connect with us! See all events

Array type cannot contain array member

All array types must define what kind of items they may contain. The "of" property must be an array of objects that describes the type of a valid item. Each entry in of, must have a type-property which must be the name of a valid schema type that is not an array - Sanity currently does not support arrays inside of arrays, also known as multidimensional arrays.

A common use case for multidimensional arrays is when you want to represent rows and columns. One possible solution in this example is to wrap each row in an object type:

export default createSchema({
  name: 'default',
  types: schemaTypes.concat([
    {
      name: 'row',
      title: 'Row',
      type: 'object',
      fields: [
        {
          name: 'columns',
          title: 'Columns',
          type: 'array',
          of: [{type: 'string'}]
        }
      ]
    },
    {
      name: 'someDocumentType',
      title: 'Some document type',
      type: 'document',
      fields: [
        {
          name: 'rows',
          title: 'Rows',
          type: 'array',
          of: [{type: 'row'}]
        }
      ]
    }
  ])
})
      

Was this article helpful?