Sanity Library Reference Docs
    Preparing search index...
    • Hook for reporting the resource the user is currently interacting with (for example, which document they're editing) so the Agent can understand their context. The hook reports on mount and again whenever the context changes.

      The two Dashboard runtimes differ in transport, but the signature is the same:

      • In an iframe (Comlink), it emits the dashboard/v1/events/agent/resource/update event.
      • In a federated app (message bus), it publishes useApplicationContext's applications.context.update topic. Reach for useApplicationContext directly in new code.

      Parameters

      Returns void

      import {useAgentResourceContext} from '@sanity/sdk-react/dashboard'

      function MyComponent() {
      const documentId = 'my-document-id'

      // Automatically updates the Agent's context whenever the document changes
      useAgentResourceContext({
      projectId: 'my-project',
      dataset: 'production',
      documentId,
      })

      return <div>Editing document: {documentId}</div>
      }