Generating forms based on some data (i.e. JSON) is quite common. You can generate React Advanced Form components, but there is no API exposed for such purpose.
Reasoning
Form shouldn't be concerned with the generation logic. Writing a simple generating function that returns React components (form or fields) is rather simple.
import*as fields from'./fields'/** * Return the generated form based on the provided JSON * that describes the fields of a form. */functiongenerateForm(props, fieldsJson) {return ( <Form {...props}> {generateFields(fieldsJson)} </Form> )}functiongenerateFields(fieldsJson) {returnfieldsJson.map((fieldParams) => {const { fieldType,...props } = fieldParamsconstField= fields[fieldType]return ( <Field {...props} /> ) })}exportdefault GeneratedForm extends React.Component {registerUser= ({ serialized }) => {}render() {const { fieldsJson } =this.propsreturngenerateForm({ action:this.registerUser, }, fieldsJson) }}
The usage of such a component would look as follows: