Automatic form generation from Zod schemas with react-hook-form
npm install @snowpact/react-rhf-zod-formAutomatic form generation from Zod schemas with react-hook-form.
- React >= 18.0.0
- react-hook-form >= 7.0.0
- zod >= 4.0.0
- @hookform/resolvers >= 3.0.0
- Zero runtime dependencies - Only peer dependencies (React, Zod, RHF)
- Automatic field type detection - Maps Zod types to form inputs
- Schema refinements - Full support for refine() and superRefine() cross-field validation
- Extensible component registry - Use your own components (inputs, layout, submit button)
- Translation support - i18next, next-intl, or any translation function
- Children pattern - Full control over layout when needed
- TypeScript first - Full type inference from Zod schemas
``bash`
npm install @snowpact/react-rhf-zod-form
`bash`
npm install react-hook-form zod @hookform/resolvers
Register your components once at app startup (e.g., app/setup.ts, _app.tsx, or main.tsx).
`tsx
import { setupSnowForm } from '@snowpact/react-rhf-zod-form';
import type { RegisteredComponentProps, FormUILabelProps } from '@snowpact/react-rhf-zod-form';
// Example custom input component
function MyInput({ value, onChange, placeholder, disabled, className, name }: RegisteredComponentProps
return (
id={name}
name={name}
type="text"
value={value ?? ''}
onChange={(e) => onChange(e.target.value)}
placeholder={placeholder}
disabled={disabled}
className={my-input ${className ?? ''}}
/>
);
}
// Example custom label component
function MyLabel({ children, required, invalid, htmlFor }: FormUILabelProps) {
return (
);
}
setupSnowForm({
translate: (key) => key,
// Essential components (a warning is logged if any are missing)
components: {
text: MyInput,
email: (props) =>
password: (props) =>
textarea: MyTextarea,
select: MySelect,
checkbox: MyCheckbox,
number: MyNumberInput,
date: MyDatePicker,
// Optional: radio, time, datetime-local, tel, url, color, file
},
formUI: {
label: MyLabel,
description: ({ children }) =>
{children}
,{message}
,