---
title: 'API reference'
description: 'Public surface of the React renderer.'
order: 8
---

# API reference

## Engine factory

```ts
import { createFormEngine } from '@schema-engine/forms';
import { elements } from './elements';
import { brandRecipe } from './brand-recipe';

export const engine = createFormEngine({ elements, recipes: [brandRecipe] });
```

`createFormEngine()` is headless. Register your widgets in `elements` and your view recipes in the `recipes` array. Use `engine.extend({ recipes: [brandRecipe] })`
to add registrations later.

## FormElements

```tsx
import type { ComponentProps } from 'react';
import { FormElements } from '@schema-engine/forms-react/primitives';

type Children = ComponentProps<typeof FormElements>['elements'];

export function FieldGroup({ name, elements, itemId }: { name: string; elements: Children; itemId: string }) {
	return <FormElements elements={elements} namePrefix={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

```tsx
import { FormRenderer } from '@schema-engine/forms-react';
import { contactForm, engine } from './react-quick-start.react';

export function Contact() {
	return <FormRenderer engine={engine} config={contactForm} onSubmit={(values) => console.log(values)} />;
}
```

The engine and `contactForm` are the ones of the [quick start](/docs/forms-react/getting-started). `FormRenderer` takes the engine as a prop. To render several forms with one engine, wrap them in `FormEngineProvider engine={engine}` and leave the prop out.

`FormRenderer` and `FormProvider` type `onSubmit`, `onAction` and `defaultValues` from the normalized config they are
given: the inferred type of `engine.defineForm` with a literal config, the output of the schema in
`engine.validateForm(json, { values })`, else `FormValues`. `onChange`, `useWatch` and live reads stay `FormValues`.
See [Submitted values](/docs/forms/form-state#submitted-values).

`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

```ts
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 work inside recipe blocks as well as ordinary form elements. [Hooks](/docs/forms-react/hooks) describes each, and [Writing a widget](/docs/forms-react/widgets) shows `useFormField` in both modes.

## Debugging

`FormDebugger` from `@schema-engine/forms-react/components/form-debugger` renders a panel with the form's steps, values and errors, for development. Render it inside a `FormRenderer`. It takes `defaultOpen` (open on mount), `showStepDetails` (each step's description in the timeline) and `showFormState` (the state, values and errors section).
