Next.js Conf 2024: Your app should be Live by Default ā€“ Watch Keynote

Creating a custom divider component in Sanity Studio

8 replies
Last updated: Jul 5, 2022
is it possible to create an empty object? I want to create a divider component that would have no fields on it, but running into an issue having no fields
Jul 4, 2022, 7:46 PM
I just add hidden:true to a random field inside if I need this
Jul 4, 2022, 8:46 PM
What User said is probably fine enough.
Jul 5, 2022, 8:08 AM
There is even a better Option for inserting non-sanity components into your studio (in V2, V3 makes basically everything possible šŸ˜‰ )One way is to use the
Sanity UI in your schemas, which help keep the UI of your studio nice and clean.An example could be:


//Divider.js
import React from 'react'

import {
  Tooltip,
  Text,
  Box,
  TextInput
} from '@sanity/ui'


// This can be styled any way you need :) 
export function createDivider({title}) {
      return {
        inputComponent: (field) => (
            <div <Container width={100} padding={4}/>),
        name: `divider${"id" + Math.random().toString(16).slice(2)}`,
        title,
        type: "string",
}


// schema where you wanna use the Divider 

import { createDivider } from "../../src/components/createDivider";


export default {
  name: 'simple',
  title: 'Simple example',
  type: 'document',
  fields: [
    {
...,
  createDivider("seo"), // the string is just the title, which can be handy as a concept :) 
...
    }
  ]
} 
Jul 5, 2022, 8:21 AM
Hot damn, that looks cool!
Jul 5, 2022, 8:26 AM
Some changes, some bling bling and here we go: You can even use groups, descriptions etc.If you want to see more happen
šŸ˜‰ Iā€™m happy to share my whole code šŸ’…
Jul 5, 2022, 8:28 AM
Dayyuumm. Nice User!
Jul 5, 2022, 8:28 AM
You should see my whole createDescription (where we can insert internal sanity links, etc. šŸ˜Ž )
Jul 5, 2022, 8:34 AM
So here you go, a nice little bundle of custom inputs to make the studio yours šŸ§‘ā€šŸŽØ
šŸ‘‰ Custom Components in the Studio
Jul 5, 2022, 10:59 AM

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?