
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI can see you're running into the classic Studio v3 migration issue with custom slug validation! The problem is that in v3, you can't use React hooks like useClient in regular functions - hooks only work in React components.
Here's how to fix your custom slug validation for Studio v3:
The key change is that the isUnique function (and similar schema functions) receives a context object as the second parameter that contains the client. Here's the corrected approach:
export function isPageSlugUnique(slug, context) {
const { document, getClient } = context;
const client = getClient({ apiVersion: "2022-02-03" });
const id = document._id.replace(/^drafts\./, "");
const params = {
draft: `drafts.${id}`,
published: id,
site: document.site,
slug,
};
const query = `!defined(*[!(_id in [$draft, $published]) && slug.current == $slug && site == $site][0]._id)`;
return client.fetch(query, params);
}Then in your schema:
{
name: 'slug',
type: 'slug',
options: {
source: 'title',
isUnique: isPageSlugUnique
}
}Key changes from v2 to v3:
useClient(), useState(), or useEffect()getClient, document, and other utilitiesclient.fetch() promise; Studio handles the async resolutiondocument from the context parameter instead of optionsThis pattern is documented in this community thread where the Sanity team clarified that isUnique receives async (value, {client, document, getClient}) as parameters.
The reason your v2 code broke is that Studio v3 removed the parts system and hooks can only be used in React components, not in schema configuration functions. The context parameter is the new way to access Studio utilities in schema functions like isUnique, initialValue, and others!
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store