import { Form, type Validator } from "json-schema-form-react"; import { useState } from "react"; import { type TSchema, Type } from "@sinclair/typebox"; import { Value, type ValueError } from "@sinclair/typebox/value"; class TypeboxValidator implements Validator { async validate(schema: TSchema, data: any) { return Value.Check(schema, data) ? [] : [...Value.Errors(schema, data)]; } } const validator = new TypeboxValidator(); const schema = Type.Object({ name: Type.String(), age: Type.Optional(Type.Number()) }); export default function JsonSchemaFormReactTest() { const [data, setData] = useState(null); return ( <>
{({ errors, dirty, reset }) => ( <>
Form {dirty ? "*" : ""} (valid: {errors.length === 0 ? "valid" : "invalid"})
)}
{JSON.stringify(data, null, 2)}
); }