How to read/display current dataset in Sanity Studio?

3 replies
Last updated: Jan 16, 2026
Hi all. I would like to read and display the current dataset being loaded on the desk. Is there a way to read the current dataset?
AI Update

Yes! There are several hooks available to read the current dataset being loaded in the Sanity Studio desk. The most direct way is to use the useDataset() hook.

Here's a simple example of how to use it:

import { useDataset } from 'sanity'

export function MyComponent() {
  const dataset = useDataset()
  
  return (
    <div>Current dataset: {dataset}</div>
  )
}

The useDataset() hook returns the name of the current dataset as a string. This is particularly useful when you need to:

  • Display different content based on the dataset (e.g., production vs. staging)
  • Show the current dataset to users in your custom Studio components
  • Conditionally render components based on which dataset is active

If you need more information beyond just the dataset name, you might also find these related hooks helpful:

  • useProjectId() - Returns the current project ID
  • useWorkspace() - Returns the entire workspace configuration, which includes the dataset, current user information, and other workspace settings
  • useClient() - Returns a configured Sanity client instance for the current project and dataset

All of these hooks are available from the 'sanity' package and can be used in any custom React component within your Studio.

You can find more details about these hooks in the Studio React Hooks documentation.

Show original thread
3 replies

Sanity โ€“ Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?