
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThe error you're seeing is expected! useFormValue only works within custom input components that are part of the form builder context. It cannot be used in document actions because actions don't have access to the form context.
According to the Sanity documentation on useFormValue, attempting to use it outside of custom input components will result in the "FormBuilder: missing context value" error you're encountering.
For document actions, you should use props.draft and props.published to access document values instead:
export function SetAndPublishAction(props: any) {
const { patch, publish } = useDocumentOperation(props.id, props.type)
const [isPublishing, setIsPublishing] = useState(false)
const dataset = useDataset()
// Access document data from props instead of useFormValue
const country = props.draft?.country || props.published?.country
useEffect(() => {
if (isPublishing && !props.draft) {
setIsPublishing(false)
}
}, [props.draft])
return {
disabled: publish.disabled,
label: isPublishing ? 'Publishing' : 'Publish & Update',
onHandle: () => {
setIsPublishing(true)
// You can now use the country value here
console.log("Country value:", country)
patch.execute([{ set: { name: "hello world" } }])
console.log("Dataset:", dataset)
publish.execute()
props.onComplete()
},
}
}Key points:
props.draft contains the current draft document (if it exists)props.published contains the published versionprops.draft first, then fall back to props.publishedprops.draft?.countryThis is the correct pattern for accessing document values in custom document actions!
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