API Reference

Engine factory

import { createFormEngine } from '@schema-engine/forms';

const engine = createFormEngine({
	elements: schemaFormRegistrations,
	recipes: [...schemaFormRecipeRegistrations, customRecipe],
});

createFormEngine() is headless. Register installed default recipes or your own recipes in the recipes array. Use engine.extend({ recipes: [customRecipe] }) to add registrations later.

FormElements

import { FormElements } from '@schema-engine/forms-react/primitives';

<FormElements elements={config.elements} namePrefix={config.name} nameStrategy="join" instanceId={itemId} />;

Fieldsets pass namePrefix={config.name}. Array items pass an arrayItemScope so paths and HTML ids are composed at render time. Do not clone child configs to change name or id.

Rendering

import { FormEngineProvider, FormRenderer } from '@schema-engine/forms-react';

<FormEngineProvider engine={engine}>
	<FormRenderer config={formConfig} onSubmit={handleSubmit} />
</FormEngineProvider>;

FormRenderer validates the config once at the form boundary and renders the resulting NormalizedFormConfig. Field renderers do not re-parse registration schemas. The selected recipe receives a ViewContext containing form metadata, active-step state, navigation, and the current slot configuration.

View hooks

import { useViewContext, useActiveStep, useFormNavigation, useViewConfig } from '@schema-engine/forms-react/hooks';
import { StepHeaderConfigSchema } from '@schema-engine/forms/recipes/built-in';

useViewContext();
useActiveStep();
useFormNavigation();
useViewConfig('header', StepHeaderConfigSchema);

Shells and slot blocks are ordinary components. Bind them to a canonical spec with defineRecipe(spec, { shell, slots }) from @schema-engine/forms-react/primitives; it requires exactly the slots the spec declares. Built-in specs are exported from @schema-engine/forms/recipes/built-in. The package root @schema-engine/forms does not re-export them.

createFormEngine() does not bind default recipes. That is not the same as omitting FormRenderer, which still lives in this package.

Form hooks

@schema-engine/forms-react/hooks exports useFormContext, useFormField, useWatch, and useFieldArray. They can be used inside recipe blocks as well as ordinary form elements.

useFormField(config) is uncontrolled: it returns defaultValue and fieldProps (with onChange and onBlur) for a native control, and the field renders for an error, warning or flag, never for a keystroke. useFormField(config, { controlled: true }) returns value, onChange(value) and onBlur() for a component that takes value and onChange props. useFormField(path) returns the state and texts of a path, with no value. In both modes the form reports the browser's validity of a native control as native facts. See Hooks.

useFieldArray returns fields and the mutation methods append, prepend, insert, swap, move, update, replace, and remove.