How to Create a Description from an Input in React

4 replies
Last updated: May 25, 2022
If I wanted to have the "slug" input show a description underneath that revealed the full (intended) URL to my site, am I right in thinking that would require a custom input component, since "description" appears to be a normal property?
Also, if I am "just" changing the component itself, I don't have to have a new/different schema/field and experience data loss if the slug fields already exist, correct? It's just a different way to "dress up" the field produced ( a misnomer, I know, since it's functional as well as aesthetic -- I am just thinking in terms of, it's all just a different way to get data stored into the system, still )
May 25, 2022, 12:53 AM
Does displaying the full url require you to perform a query?
May 25, 2022, 5:08 PM
Thanks for responding. Not necessarily -- all my slug fields are on their own separate schema, of course, and I can of course hardcode a contextual prefix leading up to the spot where the slug would go, but I'd like it to update as they write or upon "committing" the change to the slug with the handy Generate button.
As an example, if the slug field is on the document type "listing", there's no query necessary for me to hardcode "
domainname.com/listing/ " some place like the description, but as they type 123-main-st for their slug, it'd be great if the URL display string would follow in kind and ultimately join the hardcoded bit to form "domainname.com/listing/123-main-st ".
Bonus points if I could make it a true external link via React / JSX like some of the fun label experiments we've seen lately.

As far as I am currently aware we can do
amazing transformations on the actual slug itself interactively, but not the label-y kind of things like, er, the label, and the description.
Am I overthinking things again and there's a simpler, smarter approach to the use case? =P I think even more than I type, so just imagine the signal/noise ratio inside my head haha =)
May 25, 2022, 6:16 PM
Ah, I see! You can use JSX in a description, like so:
      description: (
        <p>
          This is a description with a &lt;a href='<https://www.googlecom>'&gt;link&lt;/a&gt;
        &lt;/p&gt;
      ),
But since you need it to be aware of the value of the
slug
field, you will need to do a completely custom component. You can build it yourself or implement this plugin πŸ˜‰
May 25, 2022, 6:39 PM
Thanks for the assist!
user B
brilliance strikes again!
May 25, 2022, 7:01 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.