React Components
Overview
React components and hooks for building forms with Formr. Provides pre-built components and hooks that handle form submission, validation, and error handling.
Installation
npm install formr-ui
# or
pnpm add formr-ui
# or
yarn add formr-uiRequires React 18+
Quick Start
import { useFormr, Form, Field, Errors } from 'formr-ui';
export default function ContactForm() {
const { submit, errors, pending } = useFormr({
formId: 'contact',
apiKey: process.env.NEXT_PUBLIC_FORMR_KEY,
});
return (
<Form onSubmit={submit}>
<Field
name="email"
type="email"
label="Email"
required
/>
{errors.email && <Errors field="email" message={errors.email} />}
<Field
name="message"
type="textarea"
label="Message"
required
/>
<button disabled={pending}>
{pending ? 'Submitting...' : 'Send'}
</button>
{errors._form && <Errors message={errors._form} />}
</Form>
);
}Using Hooks Directly
Components
<Form>
<Form>Wrapper component that handles form submission.
Props:
onSubmit- Submit handler functionAll standard HTML form props supported
Example:
<Field>
<Field>Input field component.
Props:
name- Field name (required)label- Field labeltype- Input type (text, email, number, textarea, etc.)All standard HTML input props supported
Example:
<Errors>
<Errors>Error display component.
Props:
field- Field name to display errors formessage- Error message to displayerrors- Error object from useFormr
Example:
Hook: useFormr(options)
useFormr(options)React hook for form management.
Options
formId- Form ID (required)apiKey- API key (optional)baseUrl- Base URL (optional)sessionId- Session ID (optional)
Returns
submit(data)- Submit functionerrors- Error objectpending- Loading statereset()- Reset errors and pending state
Example
Plain HTML Enhancement
Add the browser script to any HTML form:
The script will:
Intercept form submissions
Validate client-side (optional, UX only)
Submit via Formr API
Handle success/error states
Examples
Basic Form
Custom Styled Form
Using Hook Without Components
Features
✅ Light Client-side Validation: Required/min/max/pattern/enum for instant UX
✅ Server Validates Everything: Client checks are advisory, server is authoritative
✅ Unstyled Primitives: Bring your own styles
✅ TypeScript Support: Full TypeScript definitions
✅ Tree-shakeable: Only import what you need
Next Steps
Development Tools - Other development tools
SDK Guide - JavaScript/TypeScript SDK
API Reference - Complete API documentation
Last updated