Content has not been updated for more than 2 years, proceed with caution.
Using Theme UI with SANITY.io
Gatsby, SANITY.io and Theme UI are quickly becoming my go-to stack of development tools. Gatsby on the frontend. SANITY on the backend. Theme UI as the design system interface. Combining these three tools has been fairly smooth, but it took me a while to realize I could link Theme UI design tokens directly with SANITY block content using a serializer. Then things really took off!
Understanding data and serializers in SANITY
You can skip this next bit if you are already familiar with SANITY.
There are many upsides to this approach to content however the downside is that you need to tell SANITY how to translate your content using what is called a ‘serializer’ and the official block-content-to-react component. A serializer is a computer science term to describe programmatically changing data from one format to another.
How it works and why it matters
Using the Styled component from Theme UI you are able to link Theme UI design tokens with the block content output from SANITY. Your styles and designs are unified in one place, style it once, use it everywhere! The
<Styled/> component from Theme UI is useful in lots of other ways, it is worth a read if you aren’t familiar with it.
Example serializer with Theme UI
Happy coding! If this helps you I would love to hear about it!