@minisource/rhf
v0.1.11
Published
React Hook Form integration layer for the MiniSource design system.
Readme
@minisource/rhf
React Hook Form integration layer for the MiniSource design system.
Installation
pnpm add @minisource/rhf react-hook-formExports
Form Components
Form- RHF provider wrapperFormField- Field wrapper with Label, Description, ErrorFormInput- Input with aria-describedby/invalid wiringFormMessage- Error message displayFormLabel- Label with required indicatorFormDescription- Field description
Hooks
useForm- Thin wrapper with zodResolver presetuseFormContext- Access RHF contextuseFormField- Access current field context
Error Handling
ErrorSummary- Form-level error summary with field linkingflattenZodError- Zod error → field mapnormalizeFormError- Any error → form error statemergeErrors- Client + server error mergeparseBackendError- API error → display-friendlynormalizeBackendError- Any error shape → NormalizedErrormergeClientServerErrors- Merge client/server
Usage
import { Form, FormField, FormInput, FormMessage, useForm } from '@minisource/rhf';
import { z } from 'zod';
const schema = z.object({ email: z.string().email() });
function MyForm() {
const form = useForm({ email: '' }, schema);
return (
<Form form={form} onSubmit={form.handleSubmit(onSubmit)}>
<FormField name="email" label="Email" required>
<FormInput type="email" />
<FormMessage />
</FormField>
</Form>
);
}Architecture
This package bridges React Hook Form + Zod with the design system. No backend logic — all API/session management stays in the consuming app.
