Custom Components
Schema FormX allows the use of any UI component as a form control, not tied to a specific component library. This chapter explains how to create and register custom components.
Component Interface
A form control component needs to receive the following basic props:
Required Props
Optional Props
Any props defined in the field's props will be passed to the component.
Example:
Tutorial
Step 1: Create Component
Create an input component that supports custom props:
Step 2: Create Rating Component
Usage:
Step 3: Create Tag Component
Component Design Patterns
State Management
Use the component's own state to manage temporary values:
Register Custom Components
Global Registration
Register all custom components via the components property:
Field Specification
Specify components for specific fields via the component property:
Component Lookup Order
Form Control Lookup Order
- If
componentis specified, look up the component by name from thecomponentsobject - If
componentis not specified, default to'DefaultControl' - If not found, display error message
"error component"
Group Container Lookup Order
- If
GroupSchema.componentis specified, look up the component by name from thecomponentsobject - If not specified, look up
DefaultGroupfromcomponents - If not found, use the built-in
Groupcomponent
Note: The
Groupcomponent is an internal component and is not exported from@schema-formx/react. To customize the group container, register it viacomponents.DefaultGrouporGroupSchema.component.
Common Custom Components
Color Picker
Date Picker
Third-Party Component Library Integration
Ant Design Integration
Material-UI Integration
Component Props
Custom components receive additional props configured through schema.props:
- Use
schema.propsto pass additional configuration to components - All props defined in
schema.propsare spread onto the component - Components automatically receive
valueandonChangefor data binding - Use React.memo to optimize rendering performance for complex components