Form & Validation
useForm
Comprehensive form state management with validation, submission, and error handling.
import { useForm } from "saha-ui"Uses
Full-featured form state manager: values, touched, errors, field helpers, and validation integration.
Props
| Name | Type | Description | Default |
|---|---|---|---|
| initialValues | object | Initial form values. | - |
| validationRules | Record<string, (value: any) => string | undefined> | Optional per-field validation functions. | - |
Returns
| Name | Description |
|---|---|
| [formState, actions] | formState maps field keys to { value, error, touched }. |
| actions | Helpers: setValue, setError, setTouched, handleChange, handleBlur, validate, validateField, reset, setValues. |
Example
const [form, { handleChange, handleBlur, validate }] = useForm({ email: '', password: '' }, { email: (v) => !v ? 'Required' : undefined });Notes
Validation rules are user-provided functions that return error messages or undefined.