
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI understand your struggle! In Sanity v3 (and v4), the StructureBuilder is no longer directly importable as it was in v2. However, there's a better way to access document types and their icons in your custom widgets using the useSchema hook.
The useSchema hook gives you access to all schema types in your Studio, including their icons. Here's how to adapt your code:
import { useSchema } from 'sanity'
function YourWidget() {
const schema = useSchema()
// Get all document types
const documentTypes = schema.getTypeNames()
.map(typeName => schema.get(typeName))
.filter(type => type?.type === 'document')
return (
<div>
{documentTypes.map((docType) => {
const Icon = docType.icon
return (
<div key={docType.name}>
<Link
className={styles.link}
href={`/${getEnvironmentName()}/desk/${docType.name}`}
>
<div className={styles.iconWrapper}>
{Icon && <Icon />}
</div>
<div>{docType.title || docType.name}</div>
</Link>
</div>
)
})}
</div>
)
}useSchema() - Returns the schema object with all registered typesschema.getTypeNames() - Gets all type names in your schemaschema.get(typeName) - Gets the full type definition including icon, title, name, etc.If you specifically need to replicate the Structure Builder's default list items (which includes special handling and ordering), you can use the documentTypeListItems() method within your structure configuration, but you'll need to access it differently:
import { structureTool } from 'sanity/structure'
// In your sanity.config.js
export default defineConfig({
plugins: [
structureTool({
structure: (S) => {
// S is the Structure Builder instance
const items = S.documentTypeListItems()
// You can export or use this data here
return S.list()
.title('Content')
.items(items)
}
})
]
})However, for custom widgets outside the structure configuration, the useSchema hook approach is the recommended pattern in v3/v4.
icon property from schema types is already a React component, so you can render it directlyicon as undefined, so check before renderinggetTypeNames() may differ from Structure Builder's default ordering, which alphabetizes and applies special rulesThis approach gives you full access to document type metadata including icons, titles, and any other schema properties you need for your custom navigation widget!
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store