Do Custom React Components Need to be Input Components?

8 replies
Last updated: Feb 8, 2022
Hey! When I make a custom React component to be used in the Sanity admin, does it need to be an input component? Like, does it have to be attached to an input field, or can I just add a visual component that uses fields from the view, but doesn't take inputs?
An example of what I'm wondering about is a progress bar to be shown as a header, something that shows "your current step is X/you're at Y%" or something like that. Is that feasible?
Feb 8, 2022, 6:40 PM
import React from 'react'
import {Card, Text} from '@sanity/ui'

//...schema
{
  type: 'boolean',
  name: 'progress',
  component: ()  => (<Card><Text>Whatever!</Text></Card>)
}

Feb 8, 2022, 6:49 PM
Will that create an empty field in the db?
Feb 8, 2022, 6:51 PM
I guess an empty field isn't the worst thing in the world. 🙂
Feb 8, 2022, 6:52 PM
Nope
Feb 8, 2022, 7:08 PM
Nope
Feb 8, 2022, 7:08 PM
The Studio is more like a “mask”. So only data that’s actually inserted from input fields (or
initialValues
) ends up in the backend
Feb 8, 2022, 7:18 PM
Ah, sweet. Thanks!
Feb 8, 2022, 7:35 PM
Ah, sweet. Thanks!
Feb 8, 2022, 7:35 PM

Sanity.io – build remarkable experiences at scale

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