use-form-light
v1.2.1
Published
use-form-light is a very small React library that helps you manage forms and gives you ready-made form components with built-in checks
Maintainers
Readme
use-form-light
A lightweight form state management and validation library for React
Installation
npm install use-form-light
# or
yarn add use-form-lightUsage
Basic Usage
// Import only what you need
import { useForm } from 'use-form-light';
// or specific components
import { Form, Input, Textarea, Button } from 'use-form-light';codesandbox example https://codesandbox.io/p/sandbox/use-form-light-submit-validation-m22s8f
API
useForm
const { register, handleSubmit, errors, values, reset, validate, watch } =
useForm<T>(options);Options
defaultValues: Initial form valuesvalidationRules: Validation rules
Return Values
register: Input field registration functionhandleSubmit: Form submission handlererrors: Error message objectvalues: Current form valuesreset: Form reset functionvalidate: Manual validation functionwatch: Current specific value
Features
- Type Safety (TypeScript)
- Real-time validation
- Custom validation rules
- Default/Headless style support
- Optimized performance with minimal re-renders
- Tree-shaking support for minimal bundle size
Why use-form-light?
- Extremely Lightweight: it's significantly smaller than alternatives like react-hook-form
- Simple API: Easy to learn and use with a minimal API surface
- TypeScript First: Full type safety out of the box
- Zero Dependencies: No external dependencies, reducing bundle size
- Flexible: Supports both controlled and uncontrolled components
License
MIT
