Unlock seamless workflows and faster delivery with our latest releases – get the details

Question about handling a rich text field in the createOrReplace function with the Sanity JavaScript client.

3 replies
Last updated: Mar 20, 2024
Hi All, New to Sanity, but it’s pretty quick to pick up. Maybe a quick question, but with the Javascript client I am trying to use
createOrReplace
where one field in my schema is a rich text field
defineField({
      name: "description",
      title: "Description",
      type: 'array', 
      of: [{type: 'block'}]
    }),
When I try inserting just a string, I of course see an error in Studio that the field is an array. I can’t find any docs on how to handle this kind of field in the create. Any help?
Mar 20, 2024, 1:31 AM
Hi, I have an example for the InitialValue, but you can use it for creating a value too I think:

https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1710828491049279
Mar 20, 2024, 8:46 AM
Depending on what you’re trying to input, this package may be helpful to transform it to blocks.
Mar 20, 2024, 4:18 PM
Thanks for the info. That package looks good, but I ended up figuring it out from that other post by looking at the object that comes back in the Visualizer. I might switch to using package though as it should simplify things.
Mar 20, 2024, 5:13 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?