π¨ Block Overriding Guide
β¨ Overviewβ
The CreateOrganization
component provides powerful customization capabilities through block overriding. This pattern allows you to completely customize the form structure, validation logic, and UI components while maintaining the underlying functionality.
π Basic Overriding Patternβ
<CreateOrganization onCreateOrganization={handleSubmit}>
{({defaultBlocks, defaultBlockOrder}) => ({
blocks: {
...defaultBlocks,
// Override specific blocks here
},
blockOrder: defaultBlockOrder
})}
</CreateOrganization>
π§ Complete Customization Exampleβ
Here's a real-world example showcasing advanced Japanese organization registration:
Live Editor
<CreateOrganization onCreateOrganization={(formData) => { // Process form data console.log(formData); }}> {({defaultBlocks, defaultBlockOrder}) => ({ blocks: { ...defaultBlocks, // π― Custom Title title: { ...defaultBlocks.title, props: { ...defaultBlocks.title.props, children: 'Title', }, }, // π Rich Description with full component override description: <p style={{color: 'black'}}>Description</p>, // π’ Complex Form Override form: { ...defaultBlocks.form, props: { ...defaultBlocks.form.props, children({defaultBlocks, defaultBlockOrder}) { return { blocks: { companyInformation: { ...defaultBlocks.companyInformation, props: { ...defaultBlocks.companyInformation.props, children({defaultBlocks}) { return { blocks: { // Custom company name with pre-filled value companyName: <p style={{color: 'black'}}>Custom block</p>, // Company description with validation additionalInformation: { ...defaultBlocks.additionalInformation, props: { ...defaultBlocks.additionalInformation.props, name: 'description', label: 'Description', isRequired: true, placeholder: `Description`, }, }, }, blockOrder: [ 'companyName', 'additionalInformation' ], }; }, }, }, // Custom submit button submitButton: { ...defaultBlocks.submitButton, props: { ...defaultBlocks.submitButton.props, children: "Submit", }, }, }, blockOrder: defaultBlockOrder, }; }, }, }, }, blockOrder: defaultBlockOrder, })} </CreateOrganization>
Result
Loading...
π― Key Overriding Conceptsβ
1. Block Override Structureβ
blocks
: Object containing component definitionsblockOrder
: Array controlling render sequencedefaultBlocks
: Original component structuredefaultBlockOrder
: Original render sequence
2. Nested Overridingβ
form: {
...defaultBlocks.form,
props: {
...defaultBlocks.form.props,
children({defaultBlocks, defaultBlockOrder}) {
// Nested block overriding here
}
}
}
3. Custom Componentsβ
Replace default blocks with completely custom components:
customField: <MyCustomComponent {...props} />
π Best Practicesβ
- Always spread default props to maintain existing functionality
- Use meaningful block names for better maintainability
- Maintain blockOrder consistency unless intentionally reordering
- Implement proper validation for custom fields
- Handle loading and error states appropriately
π Benefitsβ
- π¨ Complete UI Control: Customize every aspect of the form
- π§ Flexible Validation: Implement custom validation logic
- π± Responsive Design: Maintain responsive behavior
- π State Management: Full control over form state
Pro Tip: Start with small overrides and gradually build complexity. The block overriding pattern is powerful but requires careful attention to prop spreading and component structure.