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

Should Different Sections be Separate Objects which Equate to Props in React?

5 replies
Last updated: Jun 8, 2022
So I’m working on a pretty verbose design for blog posts. There will be full size image sections, text with image on the left, text with image on the right, block quotes, ctas, etc. I’m assuming each of these should be an “object” with different fields which equate to props in react? And then in the document, I should just accept an array of objects?
Jun 8, 2022, 10:07 PM
To add onto this, there will be three types of blog posts. Full page, right aligned, and left aligned. Each of these have their own set of unique components. I was wondering if there is any way to have an “if statement” in the schema, where if the “blog post type” is right aligned then only the right aligned objects are selectable
Jun 8, 2022, 10:08 PM
It doesn’t seem like my second message is possible based on the docs from here: https://www.sanity.io/docs/array-type
Jun 8, 2022, 10:38 PM
One more question to the bunch, do you think its best to just prefix everything? so for example:
document.posts
,
object.cta
, etc so that its easily distinguishable? IDK if prefixing a document is going to cause issues
Jun 8, 2022, 10:39 PM
If you had, say, a radio, and used fieldsets that corresponded, and used the "hidden" property, the documentation mentions that property, and "readOnly", as featured it shares with objects themselves, but also intimates that the behavior would be the same as well.
Since the behavior for an object field isn't just true/false but has a callback function that can carry the document itself as a prop, you might be able to use it to refer to a sibling field (the radio itself), see what it's value is, and hide the entire set that way.
Jun 8, 2022, 10:46 PM
Hmm I see what you mean, let me give that a shot!
Jun 8, 2022, 11:19 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?