The application context to publish, or null to clear it
import {useApplicationContext} from '@sanity/sdk-react/dashboard'
import {useMemo} from 'react'
function DocumentView({documentId}: {documentId: string}) {
const context = useMemo(
() => ({resource: {id: 'my-project.production', type: 'dataset' as const}, document: {id: documentId}}),
[documentId],
)
useApplicationContext(context)
return <div>Editing {documentId}</div>
}
Publishes what this application is currently showing to the Dashboard message bus, so the host can hold the foreground application's context. Pass
nullwhen nothing is open.The context is published on mount and whenever it changes, and cleared with
nullon unmount. A change publishesnullbefore the new context, as the component has stopped showing the old one. Pass a memoised value: the hook compares by reference, so a new object on every render republishes on every render.The host reads the sending application from
message.meta.appId, so the payload carries no application ID.