How to get dataset name in Sanity v3?
In Sanity Studio v3, the Parts System has been completely replaced, so you can no longer use import client from "part:@sanity/base/client". Instead, you have a few modern approaches to get your dataset configuration:
Using the useClient hook
The most common approach in v3 is to use the useClient hook within React components:
import { useClient } from 'sanity'
function MyComponent() {
const client = useClient({ apiVersion: '2023-05-24' })
const dataset = client.config().dataset
// Use dataset...
}Important: Since useClient is a React hook, it must be called inside a React component or custom hook - you can't use it at the module level.
Alternative: Direct config import
If you need to access the dataset outside of a React component (like in a utility file), you can import your configuration directly:
import { dataset } from './sanity.config'
// Use dataset...Your sanity.config.ts (or .js) file should export your configuration:
import { defineConfig } from 'sanity'
export default defineConfig({
projectId: 'your-project-id',
dataset: 'production',
// ... other config
})
// You can also export individual values
export const { dataset, projectId } = defineConfig({
projectId: 'your-project-id',
dataset: 'production',
})For App SDK applications
If you're building with the App SDK, import from @sanity/sdk-react instead:
import { useClient } from '@sanity/sdk-react'
const client = useClient({ apiVersion: '2023-05-24' })
const dataset = client.config().datasetThe v3 migration removed the old parts-based import system in favor of standard JavaScript imports and React hooks, which provides better TypeScript support and a more modern development experience.
Show original thread14 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.