Hi,
I would like to know if it is officially supported and safe to use a <JsonForms />
component as a custom renderer inside another <JsonForms />
instance in React.
My use case is to render a nested form (with its own schema, uischema, and data) for a specific object property in the main form, and handle its validation and data updates separately.
The injected (nested) form is completely independent from the main form - it fetches its own schema and uischema asynchronously, manages its own data, and does not share or merge schemas with the parent.
Ideally, the main form should only care whether the injected form is valid, and not be responsible for merging or managing its schema or data.
Is this approach recommended? Are there any caveats regarding context, validation, or performance?
import { JsonForms } from '@jsonforms/react';
const fetchNestedSchemas = async () => {
// Simulate async fetch
return {
schema: {
type: 'object',
properties: {
nestedField: { type: 'string' }
}
},
uischema: {
type: 'Control',
scope: '#/properties/nestedField'
}
};
};
// In "injected" form
const NestedFormRenderer = () => {
const [schemas, setSchemas] = useState({ schema: null, uischema: null });
const [data, setData] = useState({ nestedField: '' });
useEffect(() => {
fetchNestedSchemas().then(setSchemas);
}, []);
if (!schemas.schema || !schemas.uischema) {
return <div>Loading nested form...</div>;
}
return (
<JsonForms
schema={schemas.schema}
uischema={schemas.uischema}
data={data}
onChange={({ data }) => setData(data)}
/>
);
};
// In renderers array:
const renderers = [
// ...other renderers,
{ tester: myTester, renderer: NestedFormRenderer }
];
// In the main form:
<JsonForms
schema={mainSchema}
uischema={mainUiSchema}
data={mainData}
renderers={renderers}
/>