@formhaus/react
Renders a JSON form definition in React: multi-step, conditional and branching forms on top of @formhaus/core. Native HTML inputs by default. Part of Formhaus.
Install
npm install @formhaus/core @formhaus/react
Requires React 18 or 19 and Node 22.12 or later.
Usage
import { FormRenderer } from '@formhaus/react';
import definition from './contact-form.json';
export function ContactPage() {
async function handleSubmit(values: Record<string, unknown>) {
await fetch('/api/contact', {
method: 'POST',
body: JSON.stringify(values),
});
}
return <FormRenderer definition={definition} onSubmit={handleSubmit} />;
}
Features
- Built-in field types, sections, repeatable groups and conditional visibility. See fields.
- Multi-step forms with lifecycle hooks, radio
autoAdvance, async step validation and branching routes. - Custom components through the
componentsprop (FieldComponentMap), plusHeadlessFormRendererto keep the built-in fields out of your bundle. Integrations: MUI, shadcn/ui. - Dynamic select options with
optionsFromandoptionsProviders. See fields. - Form events through
onFormEvent, for analytics. - Translations: the
localeprop. - Server-side validation of the same definition with
@formhaus/core/server. - Formhaus Cloud:
FormhausFormfrom@formhaus/react/cloudrenders a published form and submits to the hosted endpoint, with file uploads and the bot check. - Theming:
import '@formhaus/core/style.css', then override the--fh-*custom properties. - Server-side rendering with Next.js.
Formhaus Cloud
import { FormhausForm } from '@formhaus/react/cloud';
<FormhausForm id="form_id" />
Network
Only @formhaus/react/cloud makes network requests.
- It calls
https://api.formhaus.cc, or theapiBaseyou pass, and loads a challenge frame fromhttps://formhaus.cc. @formhaus/reactmakes no network requests.
Docs
License
MIT