🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Integration of country/region selector in Sanity.io and React discussed.

7 replies
Last updated: Aug 2, 2021
Does anyone know of an input field that implements something like this: country region/state selector>? I couldn’t find anything with a search, but it seems like a common enough UI convention that someone may have built it. I’m still getting started with Sanity (and React), and I’d like to avoid the time it would take to figure this out if something like it already exists. Thanks!
Aug 1, 2021, 7:29 PM
Hey User! I haven’t seen an exact implementation of that package, but in the past people have spread an array of countries into the
list
option on a
string
type. I just published this snippet for you.
Aug 2, 2021, 5:15 PM
Oh that’s lovely. Thanks,
user M
! I’ve still got my eye on integrating this component somehow, but this is a welcome improvement while I learn more about Sanity and React.
Aug 2, 2021, 5:21 PM
Happy to help! You could probably integrate that package you mentioned by building a custom input component, but I find that when you’re first getting started that can be rough!
Aug 2, 2021, 5:24 PM
Yeah, I’ve started watching some of the custom input tutorial videos, but it’s a matter of balancing learning time with all the other bits I need to code. Some day!
Aug 2, 2021, 5:25 PM
If I use string fields for Country and Region for now, how challenging will it be to migrate data from those fields to (what I assume will be) string fields inside a custom input component in the future? Is there anything I should be doing now to make that process easier?
Aug 2, 2021, 5:30 PM
If you do go ahead and make a custom input component in the future it should be fairly straight forward to write a script that patches the string field’s values into the new custom component. It looks daunting at first but is surprisingly simple once you start tackling it.
Aug 2, 2021, 5:34 PM
Glad to hear it. I’m sure I’ll be back here with other questions before I even get that far, but it’s encouraging to know it’s simpler than it looks. 😀
Aug 2, 2021, 5:37 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?