Sanity Library Reference Docs
    Preparing search index...

    Function useAgentResourceContext

    • Hook for emitting agent resource context updates to the Dashboard. This allows the Agent to understand what resource the user is currently interacting with (e.g., which document they're editing).

      The hook will automatically emit the context when it changes, and also emit the initial context when the hook is first mounted.

      Parameters

      Returns void

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

      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>
      }