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

Custom component PatchEvent.from(set(value)) not working

4 repliesLast updated: Nov 29, 2025

I am trying to set a value with a custom component, but I am getting no response when the
PatchEvent.from(set(value));
executes.
AI Update

Based on the documentation, the most common reason PatchEvent.from(set(value)) appears to do nothing is that you're not actually calling the onChange callback with the PatchEvent.

PatchEvent.from() is just an action creator - it creates the patch event but doesn't trigger any updates by itself. You need to pass it to the onChange prop that Sanity provides to your custom component:

// ❌ This won't work - just creates the event but doesn't dispatch it
PatchEvent.from(set(value));

// ✅ This will work - passes the event to onChange
onChange(PatchEvent.from(set(value)));

Here's a complete example of a working custom input component:

import { set, unset } from 'sanity'

export function MyCustomInput(props) {
  const { onChange, value } = props
  
  const handleChange = (event) => {
    const inputValue = event.target.value
    
    // Create and dispatch the patch event
    onChange(
      inputValue 
        ? PatchEvent.from(set(inputValue))
        : PatchEvent.from(unset())
    )
  }
  
  return (
    <input 
      type="text" 
      value={value || ''} 
      onChange={handleChange}
    />
  )
}

Key points:

If you're still not seeing updates after calling onChange, double-check:

You can find more details in the PatchEvent documentation and this community answer about the same issue.

Show original thread
4 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