raw Examples
The raw property serves as the "Escape Hatch". It allows you to bypass the declarative JSON configuration and use the native Sanity Structure Builder API directly for a specific list item.
When to use raw?
You should only use raw when you need functionality that isn't currently supported by the plugin's declarative schema, such as:
- Customizing the document list sorting or grouping.
- Using complex
childresolvers. - Creating completely custom views or components in the desk.
Constraints & Limitations
While the raw property is powerful, it comes with specific constraints:
- Return Type: The
rawcallback must return anS.listItem()(or its equivalent piped output). It does not supportS.list()or other builders as the root return value. - Access Control: When you use
raw, the plugin's automaticrolesandworkspacesfiltering only applies to the top-level list item itself. If you define nestedchildrenwithin therawcallback using the native API, you are responsible for handling any access control logic manually for those nested items.
Basic Usage
In this example, we use the native S.listItem() to create a highly customized entry.
{
raw: (S) =>
S.listItem()
.title('Custom Sorted Posts')
.child(
S.documentTypeList('post')
.title('Posts by Title')
.filter('_type == "post"')
.defaultOrdering([{ field: 'title', direction: 'asc' }])
),
}Accessing Context
The raw callback also provides access to the Sanity context, which includes the currentUser, dataset, projectId, and more.
{
raw: (S, context) => {
const { currentUser } = context;
return S.listItem()
.title(`My Assigned Tasks (${currentUser?.name})`)
.child(
S.documentTypeList('task')
.filter('_type == "task" && assignee._ref == $userId')
.params({ userId: currentUser?.id })
);
},
}Use Sparingly
While powerful, using raw breaks away from the declarative benefits of this plugin. We recommend using it only when the standard properties (schemaType, filter, singleton, etc.) are insufficient for your needs.
