
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeGood news! You can absolutely access the document's data in your custom view component, including the language field. The key is that while getDefaultDocumentNode only receives the document ID, your custom view component (in this case IframePreview) receives much more detailed props, including the actual document data.
Your IframePreview component receives a document prop that contains the current document's data, including the displayed version. You can access the language field directly from there:
// IframePreview.js
export function IframePreview(props) {
const { document, options } = props;
// Access the language from the document's displayed version
const language = document.displayed?.language || 'en';
const previewURL = options.previewURL;
return (
<iframe
src={`${previewURL}?lang=${language}`}
// ... other iframe props
/>
);
}Your getDefaultDocumentNode setup stays simple - just pass the static options you need:
export const getDefaultDocumentNode = (props) => {
if (props.schemaType === "page") {
return S.document().views([
S.view.form().icon(FaEdit).title("Edit"),
S.view
.component(IframePreview)
.options({ previewURL }) // Just pass static config
.title("Preview")
.icon(FaEye),
]);
}
};Your custom view component receives these useful props:
document.displayed - The current state of the document being edited (includes all fields like language)document.draft - The draft version (if it exists)document.published - The published versiondocumentId - The document's IDschemaType - The schema typeoptions - Whatever you passed in .options()The displayed version is particularly useful because it shows what the editor is currently looking at (draft if it exists, otherwise published).
The component will automatically re-render when the document changes, so if the editor changes the language field, your preview will update accordingly with the new language value.
This approach is much cleaner than trying to run GROQ queries in the Structure Builder configuration - you let Sanity handle the document data flow and just consume it in your component. The Component View documentation covers more about how custom document views work with document data in Sanity Studio.
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