Sanity App SDK
    Preparing search index...

    Function useNavigateToStudioDocument

    • Hook that provides a function to navigate to a given document in its parent Studio.

      Uses the projectId and dataset properties of the DocumentHandle you provide to resolve the correct Studio. This will only work if you have deployed a studio with a workspace with this projectId / dataset combination.

      Parameters

      • documentHandle: DocumentHandle

        The document handle for the document to navigate to

      • OptionalpreferredStudioUrl: string

        The preferred studio url to navigate to if you have multiple studios with the same projectId and dataset

      Returns NavigateToStudioResult

      An object containing:

      • navigateToStudioDocument - Function that when called will navigate to the studio document

      If you write your own Document Handle to pass to this hook (as opposed to a Document Handle generated by another hook), it must include values for documentId, documentType, projectId, and dataset.

      import {useNavigateToStudioDocument, type DocumentHandle} from '@sanity/sdk-react'
      import {Button} from '@sanity/ui'
      import {Suspense} from 'react'

      function NavigateButton({documentHandle}: {documentHandle: DocumentHandle}) {
      const {navigateToStudioDocument} = useNavigateToStudioDocument(documentHandle)
      return (
      <Button
      onClick={navigateToStudioDocument}
      text="Navigate to Studio Document"
      />
      )
      }

      // Wrap the component with Suspense since the hook may suspend
      function MyDocumentAction({documentHandle}: {documentHandle: DocumentHandle}) {
      return (
      <Suspense fallback={<Button text="Loading..." disabled />}>
      <NavigateButton documentHandle={documentHandle} />
      </Suspense>
      )
      }