Form using react hooks form very easy to use
npm install react-hook-form-easy-accessA composable, flexible form library for React, built on top of react-hook-form.
- Initial release
- Fix: update README.md add demo application https://codesandbox.io/p/sandbox/react-hook-form-easy-access-pxclnl
- Fix: add export type FormRef
- Fix: add props classNameLabel and classNameError to FormField component
- Fix: add props className to Form component
- Fix: call onchange event from different component
- 🧩 Composable: Build forms using Form and FormField components.
- 🛡️ Schema Validation: Built-in support for Zod, Yup, Joi, Superstruct, and Vest (auto-detected).
- 🔄 Dynamic Fields: Easy management of array fields with useFormField.
- 💅 Headless UI: Full control over styling (Tailwind ready).
- 🚀 Performance: Optimized renders using react-hook-form.
How to install react-hook-form-easy-access:
``bash
npm install react-hook-form-easy-access react-hook-form @hookform/resolvers
Demo Application
demo application: https://codesandbox.io/p/sandbox/react-hook-form-easy-access-pxclnl
Usage
$3
The
Form component acts as a provider, and FormField handles individual inputs.`tsx
import { Form, FormField } from "react-hook-form-easy-access";
import { z } from "zod";// 1. Define Schema
const schema = z.object({
username: z.string().min(3, "Username must be at least 3 chars"),
email: z.string().email("Invalid email"),
});
export default function LoginForm() {
const handleSubmit = (data) => {
console.log("Form Data:", data);
};
return (
schema={schema}
onSubmit={handleSubmit}
defaultValues={{ username: "", email: "" }}
className="space-y-4"
>
);
}
`$3
If you need access to form methods like
reset, setValue, or isPending inside the form, use the render prop pattern.`tsx
`$3
Use
useFormField (which wraps useFieldArray) to handle dynamic lists.`tsx
import { Form, FormField } from "react-hook-form-easy-access";function DynamicList({ useFieldArray }) {
// This hook must be used inside a component that is a child of
useFieldArray directly.
const { fields, append, remove } = useFormField("items"); return (
{fields.map((field, index) => (
items.${index}.name}>
))}
);
}// Usage
`API Reference
$3
The root component that provides context to all fields.
| Prop | Type | Description |
|------|------|-------------|
|
schema | SchemaConfig \| any | Validation schema (Zod, Yup, etc.). Auto-detected. |
| onSubmit | (data: T) => void | Function called on successful submission. |
| defaultValues | DefaultValues | Initial values for the form. |
| children | ReactNode \| (methods) => ReactNode | Form content. Can be a function to access form methods. |
| className | string | CSS class for the