✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

How to Wrap Nested Arrays in Objects

4 replies
Last updated: Jul 16, 2020
I'm reading about this limitation with
array
types

Due to a limitation in the data store, arrays may not currently contain arrays. Wrap nested arrays in objects.
Does anyone have an example of wrapping nested arrays in objects? I'm not quite sure I understand how that would be setup.
Jul 16, 2020, 3:30 PM
Figured it out! This ties back to my question from yesterday
Since you can't nest arrays within arrays, I needed to wrap things with an extra layer to get the "page builder" effect I was looking for.
Jul 16, 2020, 4:14 PM
First, I created this schema which has the types I want to allow in my page builder
export default {
	name: 'clusterItems',
	type: 'array',
	title: 'Cluster Items',
	of: [
		{
			type: 'image'
		},
		{
			type: 'video'
		},
		{
			type: 'textContent'
		}
	]
};
Jul 16, 2020, 4:15 PM
Then I created this schema which I use in the actual editor

export default {
	name: 'cluster',
	type: 'object',
	title: 'Cluster',
	fields: [
		{
			name: 'items',
			type: 'clusterItems',
			title: 'Items'
		}
	]
};
Jul 16, 2020, 4:15 PM
Thanks for sharing back the examples Mark, really appreciated đź‘Ť
Jul 16, 2020, 7:01 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?