BetaObject containing:
action - Action to perform (currently only 'edit' is supported). Will prompt a picker if multiple handlers are available.intentId - Specific ID of the intent to dispatch. Either action or intentId is required.documentHandle - The document handle containing document ID, type, and either:
projectId and dataset for traditional dataset sources, like {documentId: '123', documentType: 'book', projectId: 'abc123', dataset: 'production'}source for media library, canvas, or dataset sources, like {documentId: '123', documentType: 'sanity.asset', source: mediaLibrarySource('ml123')} or {documentId: '123', documentType: 'sanity.canvas.document', source: canvasSource('canvas123')}paremeters - Optional parameters to include in the dispatch; will be passed to the resolved intent handlerAn object containing:
dispatchIntent - Function to dispatch the intent messageimport {useDispatchIntent} from '@sanity/sdk-react'
import {Button} from '@sanity/ui'
import {Suspense} from 'react'
function DispatchIntentButton({documentId, documentType, projectId, dataset}) {
const {dispatchIntent} = useDispatchIntent({
action: 'edit',
documentHandle: {documentId, documentType, projectId, dataset},
})
return (
<Button
onClick={() => dispatchIntent()}
text="Dispatch Intent"
/>
)
}
// Wrap the component with Suspense since the hook may suspend
function MyDocumentAction({documentId, documentType, projectId, dataset}) {
return (
<Suspense fallback={<Button text="Loading..." disabled />}>
<DispatchIntentButton
documentId={documentId}
documentType={documentType}
projectId={projectId}
dataset={dataset}
/>
</Suspense>
)
}
A hook for dispatching intent messages to the Dashboard with a document handle. This allows applications to signal their intent to pass the referenced document to other applications that have registered the ability to perform specific actions on that document.