Skip to main content
Studio hooks provide access to Studio-level context and functionality. These hooks must be used within components rendered inside the Studio.

useTools

Access the configured Studio tools.
import {useTools} from 'sanity'

function ToolSwitcher() {
  const tools = useTools()
  
  return (
    <div>
      {tools.map(tool => (
        <button key={tool.name}>
          {tool.icon && <tool.icon />}
          {tool.title}
        </button>
      ))}
    </div>
  )
}
tools
Tool[]
Array of configured Studio tools
name
string
Tool identifier (used in URL)
title
string
Display title
icon
ComponentType
Tool icon component
component
ComponentType
Tool component to render

useWorkspace

Access the current workspace configuration.
import {useWorkspace} from 'sanity'

function WorkspaceInfo() {
  const workspace = useWorkspace()
  
  return (
    <div>
      <h2>{workspace.title}</h2>
      <p>Project: {workspace.projectId}</p>
      <p>Dataset: {workspace.dataset}</p>
    </div>
  )
}
workspace
Workspace
Current workspace configuration
name
string
Workspace identifier
title
string
Workspace display title
projectId
string
Sanity project ID
dataset
string
Dataset name
schema
Schema
Workspace schema
tools
Tool[]
Configured tools

useWorkspaces

Access all configured workspaces (for multi-workspace Studios).
import {useWorkspaces} from 'sanity'

function WorkspaceSelector() {
  const workspaces = useWorkspaces()
  
  return (
    <select>
      {workspaces.map(ws => (
        <option key={ws.name} value={ws.name}>
          {ws.title}
        </option>
      ))}
    </select>
  )
}
workspaces
Workspace[]
Array of all configured workspaces

useColorScheme

Access and control the Studio color scheme.
import {useColorScheme} from 'sanity'

function ThemeSwitcher() {
  const {scheme, setScheme} = useColorScheme()
  
  return (
    <button onClick={() => setScheme(scheme === 'dark' ? 'light' : 'dark')}>
      {scheme === 'dark' ? '☀️' : '🌙'}
    </button>
  )
}
scheme
'light' | 'dark' | 'system'
Current color scheme
setScheme
(scheme: 'light' | 'dark' | 'system') => void
Function to change the color scheme

useFeatureEnabled

Check if a Studio feature is enabled.
import {useFeatureEnabled} from 'sanity'

function ConditionalFeature() {
  const isEnabled = useFeatureEnabled('myFeature')
  
  if (!isEnabled) return null
  
  return <div>Feature content</div>
}
featureName
string
required
Name of the feature to check
enabled
boolean
Whether the feature is enabled

useCurrentUser

Access information about the currently logged-in user.
import {useCurrentUser} from 'sanity'

function UserProfile() {
  const currentUser = useCurrentUser()
  
  if (!currentUser) return <div>Not logged in</div>
  
  return (
    <div>
      <img src={currentUser.profileImage} alt={currentUser.name} />
      <h3>{currentUser.name}</h3>
      <p>{currentUser.email}</p>
    </div>
  )
}
user
CurrentUser | null
Current user information or null if not authenticated
id
string
User ID
name
string
User’s display name
email
string
User’s email address
profileImage
string
URL to user’s profile image
roles
Role[]
User’s roles in the project

useStudioUrl

Generate URLs to different parts of the Studio.
import {useStudioUrl} from 'sanity'

function DocumentLink({documentId, documentType}: Props) {
  const {resolveUrlFor} = useStudioUrl()
  
  const url = resolveUrlFor({
    intent: 'edit',
    id: documentId,
    type: documentType
  })
  
  return <a href={url}>Edit document</a>
}
resolveUrlFor
(params: UrlParams) => string
Function to resolve Studio URLs
params
object
required
URL parameters
intent
'edit' | 'create'
required
Intent type
id
string
Document ID (for edit intent)
type
string
Document type
params
Record<string, string>
Additional query parameters

useConnectionState

Monitor the Studio’s connection to Sanity’s backend.
import {useConnectionState} from 'sanity'

function ConnectionStatus() {
  const connectionState = useConnectionState()
  
  return (
    <div>
      Status: {connectionState}
    </div>
  )
}
connectionState
'connected' | 'connecting' | 'reconnecting' | 'disconnected'
Current connection state

useSource

Access the current source (workspace) context.
import {useSource} from 'sanity'

function SourceInfo() {
  const source = useSource()
  
  return (
    <div>
      <p>Project: {source.projectId}</p>
      <p>Dataset: {source.dataset}</p>
    </div>
  )
}
source
Source
Source configuration and utilities
projectId
string
Project ID
dataset
string
Dataset name
getClient
(options: SourceClientOptions) => SanityClient
Function to get a configured client

Example: Custom Status Bar

import {
  useCurrentUser,
  useConnectionState,
  useWorkspace,
  useColorScheme
} from 'sanity'
import {Card, Flex, Text, Badge} from '@sanity/ui'

function StatusBar() {
  const user = useCurrentUser()
  const connection = useConnectionState()
  const workspace = useWorkspace()
  const {scheme, setScheme} = useColorScheme()
  
  return (
    <Card padding={3} borderTop>
      <Flex justify="space-between" align="center">
        <Flex gap={3} align="center">
          <Badge tone={connection === 'connected' ? 'positive' : 'critical'}>
            {connection}
          </Badge>
          <Text size={1} muted>
            {workspace.title}{user?.name}
          </Text>
        </Flex>
        <button onClick={() => setScheme(scheme === 'dark' ? 'light' : 'dark')}>
          Toggle theme
        </button>
      </Flex>
    </Card>
  )
}

Build docs developers (and LLMs) love