
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeNo, you cannot directly update or query custom document badges from a custom document action. This is an important architectural limitation to understand.
Document badges exist purely in the Studio UI layer and are not persisted as part of the actual document data. According to the Document Badges documentation, badge values are not written to the document itself - they're computed and displayed on-the-fly based on the document's current state.
When you create a custom badge, it receives these properties:
id - The document IDtype - The schema typedraft - The draft document (if any)published - The published document (if any)Badges read from the document state and display information, but they don't store queryable data themselves.
If you need to track status or metadata that both document actions and badges can access, consider these patterns:
status or workflowState) that both your custom action and badge can read fromuseDocumentOperation hookHere's a simple example pattern:
// In your schema
{
name: 'myDocument',
type: 'document',
fields: [
{
name: 'status',
type: 'string',
options: {
list: ['draft', 'review', 'approved']
}
}
]
}
// Custom badge reads the status
export function StatusBadge(props) {
const status = props.published?.status || props.draft?.status
return {
label: status?.toUpperCase(),
color: status === 'approved' ? 'success' : 'default'
}
}
// Custom action updates the status
export function ApproveAction(props) {
// Use useDocumentOperation to patch the document
// and update the status field
}This way, your document action modifies the actual document data, and your badge displays that data - creating a workflow where both features work together through the document's content rather than trying to communicate directly.
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