Sanity V3 custom checkbox component error with part: imports

13 replies
Last updated: Nov 29, 2025
Trying to create new custom checkbox input component in Sanity V3. But getting error in attached screenshot.import React from “react”;


// Important items to allow form fields to work properly and patch the dataset.
import { PatchEvent, set } from "part:@sanity/form-builder/patch-event";
import FormField from "part:@sanity/components/formfields/default";

// Import the TextInput from UI
import { Checkbox } from "@sanity/ui";

const Checkboxcomponent = React.forwardRef((props, ref) => {
  const { type, onChange } = props;
  return (
    <FormField label={type.title} description={type.description}>
      <Checkbox
        ref={ref}
        placeholder={type.placeholder}
        value={props.value}
        onChange={(event) => {
          console.log(event, "event");
          // onChange(PatchEvent.from(set(event.target.value)));
        }}
      />
    </FormField>
  );
});

export default Checkboxcomponent;
AI Update

The issue you're encountering is because you're using Sanity Studio v2 syntax in what appears to be a v3 project. The imports from part:@sanity/form-builder and part:@sanity/components don't exist in Studio v3 - these were the v2 APIs.

Here's how to create a custom checkbox input component for Sanity Studio v3:

import React from "react";
import { set, unset } from "sanity";
import { Stack, Checkbox } from "@sanity/ui";

const CheckboxComponent = React.forwardRef((props, ref) => {
  const { elementProps, onChange, value = false } = props;
  
  const handleChange = React.useCallback(
    (event) => {
      const isChecked = event.currentTarget.checked;
      onChange(isChecked ? set(isChecked) : unset());
    },
    [onChange]
  );

  return (
    <Stack space={3}>
      <Checkbox
        {...elementProps}
        ref={ref}
        checked={value}
        onChange={handleChange}
      />
    </Stack>
  );
});

export default CheckboxComponent;

Then in your schema, use it like this:

{
  name: 'myCheckboxField',
  type: 'boolean',
  components: {
    input: CheckboxComponent
  }
}

Key differences from v2 to v3:

  1. No more part: imports - Import directly from sanity and @sanity/ui
  2. PatchEvent is gone - Just use set() and unset() directly from the sanity package
  3. No FormField wrapper needed - Studio v3 handles labels/descriptions automatically
  4. Props structure changed - You get elementProps, onChange, value directly
  5. Schema integration - Use components.input property instead of inputComponent

For a complete guide on creating custom input components in v3, check out this official guide. If you're migrating existing v2 components, the migration guide has detailed information on all the API changes.

Show original thread
13 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.

Was this answer helpful?