You can render personalized components by providing a customComponent object to the SchemaForm component. The keys in this object correspond to the $componentType value defined in your JSON schema.
Depending on the type of the schema field, the function signature for your custom component changes:
For non-object types
When the schema type is not object, your function receives:
item (object): The JSON schema information for the current component (id, title, etc.).form (object): The Ant Design form instance.required (boolean): Indicates if the field is mandatory.
Signature: ({ item, form, required }) => React.Node
For object types
When the schema type is object (or contains oneOf), your function receives:
item (object): The JSON schema information.form (object): The Ant Design form instance.element (React.ReactNode): The React component to be rendered.
Signature: ({ item, form, element }) => React.Node
import SchemaForm from 'antd-schema-form';
import 'antd-schema-form/style/antd-schema-form.css';
const customComponent = {
// For non-object types
custom({ item, form, required }) {
return <Input placeholder="Custom Component" required={ required } />;
},
// For object types
objectCustom({ item, form, element }) {
return <div className="custom-wrapper">{ element }</div>;
},
};
const schemaJson = {
id: '$root',
type: 'string',
title: 'Custom Component Example',
$componentType: 'custom' // Matches the key in customComponent
};
// Usage
<SchemaForm json={ schemaJson } customComponent={ customComponent } />