Joint session with Vercel: How to build intelligent storefronts (May 15th)

How to implement withDocument in Sanity v3?

7 repliesLast updated: Nov 29, 2025

Hi team, I am currently migrating to v3.
How to implement the "withDocument" ?

import { withDocument } from 'part:@sanity/form-builder';
AI Update

In Sanity Studio v3, withDocument from part:@sanity/form-builder has been replaced by the useFormValue hook. The parts system was completely removed in v3, so you'll need to refactor your custom input components to use hooks instead.

Here's how to migrate:

Old v2 pattern:

import { withDocument } from 'part:@sanity/form-builder';

const MyCustomInput = withDocument(({ document, type, value, onChange }) => {
  // Access document here
  console.log(document)
  return <input ... />
})

New v3 pattern:

import { useFormValue } from 'sanity'

const MyCustomInput = (props) => {
  // Get the entire document with an empty array
  const document = useFormValue([])
  
  // Or get specific fields
  const title = useFormValue(['title'])
  const authorId = useFormValue(['author', '_ref'])
  
  return <input ... />
}

Key differences:

The useFormValue hook only works within the form builder context (inside custom input components). If you need document data in other contexts like document actions, you'll need to use different approaches like the useDocumentOperation hook or fetch data via the Sanity client.

Show original thread
7 replies

Was this answer helpful?

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.

Related contributions