schema-components - v3.7.0
    Preparing search index...

    Interface SchemaComponentProps<T, SchemaRef, Mode>

    Props accepted by SchemaComponent.

    The generic parameters carry the inferred schema shape through to value, onChange, and fields so a typed schema prop drives typed props on the rest of the component.

    interface SchemaComponentProps<
        T = unknown,
        SchemaRef extends string | undefined = undefined,
        Mode extends SchemaIoSide = "output",
    > {
        schema: RejectUnrepresentableZod<T>;
        schemaRef?: SchemaRef;
        io?: Mode;
        value?: InferSchemaValue<T, SchemaRef, Mode>;
        onChange?: (value: InferSchemaValue<T, SchemaRef, Mode>) => void;
        validate?: boolean;
        onValidationError?: (error: unknown) => void;
        onError?: (error: SchemaError) => void;
        onDiagnostic?: (diagnostic: Diagnostic) => void;
        strict?: boolean;
        fields?: InferFields<T, SchemaRef>;
        meta?: SchemaMeta;
        readOnly?: boolean;
        writeOnly?: boolean;
        description?: string;
        widgets?: WidgetMap;
        idPrefix?: string;
    }

    Type Parameters

    • T = unknown
    • SchemaRef extends string | undefined = undefined
    • Mode extends SchemaIoSide = "output"
    Index

    Properties

    Zod schema, JSON Schema object, or OpenAPI document.

    Zod 4 types that cannot round-trip through z.toJSONSchema() (bigint, date, map, set, symbol, function, undefined, void, nan, codec) are rejected at the type level via RejectUnrepresentableZod. Runtime conversion would throw SchemaNormalisationError with kind zod-type-unrepresentable — the static rejection surfaces the same failure at compile time.

    schemaRef?: SchemaRef

    For OpenAPI / JSON Schema documents: a $ref string pointing at the sub-schema to render — e.g. "#/components/schemas/User" or "/users/post".

    Named schemaRef (not ref) so the prop survives the React / preact/compat createElement boundary, which strips the reserved ref name from the vnode prop bag.

    io?: Mode

    Which side of every transform / pipe / codec to render.

    • "output" (default) — renderer draws the OUTPUT side of the schema. For a z.codec(z.string(), z.number(), …) chain this renders a number input. value and onChange therefore carry the OUTPUT shape, and validate runs safeEncode (the reverse direction) so user-supplied OUTPUT values are validated against the codec.
    • "input" — renderer draws the INPUT side instead. For the same codec this renders a string input, value and onChange carry the INPUT shape, and validate runs safeParse (the forward direction).

    The choice is propagated through normaliseSchemanormaliseZod4z.toJSONSchema(..., { io }) so a single source of truth drives both the rendered JSON Schema shape and the validation direction. Has no effect for plain JSON Schema or OpenAPI inputs — those advertise a single canonical shape.

    Current value to render. Typed against InferSchemaValue<T, SchemaRef, Mode> so the prop tracks the schema's inferred shape for the chosen io direction.

    Falls back to unknown when the schema's value type cannot be statically inferred (runtime Record<string, unknown> JSON Schemas, OpenAPI documents without a ref, etc.), so untyped call sites still compile.

    Use InferredOutputValue or InferredInputValue to narrow a value declared at the call site:

    const user: InferredOutputValue<typeof userSchema> = { ... };
    <SchemaComponent schema={userSchema} value={user} readOnly />
    onChange?: (value: InferSchemaValue<T, SchemaRef, Mode>) => void

    Called when the value changes (editable fields). The parameter shares the same shape as SchemaComponentProps.value so a controlled component can round-trip the value through React state without re-shaping.

    Falls back to unknown for schemas whose value type cannot be statically inferred — see SchemaComponentProps.value.

    validate?: boolean

    Run schema.safeParse() on change and surface errors via onValidationError.

    onValidationError?: (error: unknown) => void

    Called with the ZodError when validation fails.

    onError?: (error: SchemaError) => void

    Called when schema normalisation or rendering fails.

    onDiagnostic?: (diagnostic: Diagnostic) => void

    Called with each diagnostic emitted during schema processing.

    strict?: boolean

    When true, any diagnostic becomes a thrown error.

    Per-field meta overrides — nested object mirroring schema shape.

    meta?: SchemaMeta

    Meta overrides applied to the root schema.

    readOnly?: boolean

    Convenience: sets readOnly on all fields.

    writeOnly?: boolean

    Convenience: sets writeOnly on all fields.

    description?: string

    Convenience: sets description on the root.

    widgets?: WidgetMap

    Instance-scoped widgets — override context and global widgets.

    idPrefix?: string

    Prefix used for every input id/label htmlFor in this component subtree. Defaults to a per-instance value from useId() so multiple <SchemaComponent> instances on the same page never collide. Override for deterministic ids in screenshot tests.