Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

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?